我正在尝试从集合任务“step”中添加数组中的对象,而不删除数组中已经存在的对象
queryDocumentSnapshot.ref.set({steps:[{title:newStep,completed:false}]});
alert('This task has been updated');但是当我使用set时,它删除了所有旧的字段。如何在不删除的情况下更新(在数组中添加新元素)?
发布于 2021-04-18 01:28:32
如doc中所述,您需要使用arrayUnion
queryDocumentSnapshot.ref.update({
steps: firebase.firestore.FieldValue.arrayUnion({title:newStep,completed:false})
})
.then(() => {
alert('This task has been updated');
});https://stackoverflow.com/questions/67140800
复制相似问题