我想更新Firestore中数组中对象的completed
属性,但是我不知道如何到达数组中的特定元素。该图像将显示结构。
我已经走了这么远,但是不知道如何选择,例如数组中的第1项。我当时在考虑使用其ID(它具有id属性),但不知道如何到达那里。
const businessRef = db.collection('approvedBusinesses').doc(businessId)
try {
businessRef.update({
[`bookings.${currentDate} ????? `]: true // what to add after currentDate?
})
顺便说一下,这就是数组的创建方式(以及其他对象如何推入数组)
const bookingObj = {
carro: 'PASSA_CARRO',
completed: false,
userId: userObject.uid,
}
businessRef.update({
[`bookings.${currentDate}`]: firebase.firestore.FieldValue.arrayUnion(bookingObj),
})
答案 0 :(得分:2)
Firestore没有允许您通过其索引更新数组中现有项目的操作。
要更新阵列中的现有项目,您将需要:
我很确定以前已经问过这个问题,所以让我看看是否有一个例子的答案。
另请参阅: