我已经能够根据产品的类别编写代码以将对象添加到相应的数组中,但是使用相同的逻辑我无法删除它。有人知道怎么做吗?
Firestore组织(要删除的字段带有红色箭头,数组组件位于文档中):
async addComponentToBuild(userId, buildId, component) {**//THIS METHOD IS WORKING**
const fieldName = `components.${component.CATEGORY}`
const updateObj = {};const compObj ={}
compObj[component.PRODUCTNAME] = component
updateObj[fieldName] = FieldValue.arrayUnion(compObj)
return this.usersDb.doc(userId).collection('builds').doc(buildId)
.update(updateObj)
.then(doc => { `Component ${component.PRODUCTNAME} added`})
.catch(handleError)
}
async deleteComponentFromBuild(userId, buildId, componentId) {
var component = await this.getSingleComponent(componentId)
var fieldName = `components.${component.CATEGORY}`//.${componentId}
const updateObj = {}
updateObj[fieldName] = FieldValue.arrayRemove(componentId)
return this.usersDb.doc(userId).collection('builds').doc(buildId).update(updateObj)
.then(doc =>
{ `Component ${component.PRODUCTNAME} deleted`}
)
.catch(handleError)
}