I would like to update the pleted
property of an object in an array in Firestore, but I have no idea how to reach that specific element in the array. The image will show the structure.
I have e up this far but don't know how to choose, for example, item 1 in the array. I was thinking of using its ID (it has an id property) but don't know how to get there.
const businessRef = db.collection('approvedBusinesses').doc(businessId)
try {
businessRef.update({
[`bookings.${currentDate} ????? `]: true // what to add after currentDate?
})
By the way, this is how the array was created (and how other objects are pushed to it)
const bookingObj = {
carro: 'PASSA_CARRO',
pleted: false,
userId: userObject.uid,
}
businessRef.update({
[`bookings.${currentDate}`]: firebase.firestore.FieldValue.arrayUnion(bookingObj),
})
I would like to update the pleted
property of an object in an array in Firestore, but I have no idea how to reach that specific element in the array. The image will show the structure.
I have e up this far but don't know how to choose, for example, item 1 in the array. I was thinking of using its ID (it has an id property) but don't know how to get there.
const businessRef = db.collection('approvedBusinesses').doc(businessId)
try {
businessRef.update({
[`bookings.${currentDate} ????? `]: true // what to add after currentDate?
})
By the way, this is how the array was created (and how other objects are pushed to it)
const bookingObj = {
carro: 'PASSA_CARRO',
pleted: false,
userId: userObject.uid,
}
businessRef.update({
[`bookings.${currentDate}`]: firebase.firestore.FieldValue.arrayUnion(bookingObj),
})
Share
Improve this question
edited Jun 16, 2020 at 20:44
uber
asked Jun 16, 2020 at 20:29
uberuber
5,1136 gold badges33 silver badges65 bronze badges
0
1 Answer
Reset to default 5Firestore does not have an operation that allows you to update an existing item in an array by its index.
To update an existing item in the array, you will need to:
- Read the entire document into your application.
- Modify the item in the array in your application code.
- Write back the entire array to the document.
I'm pretty sure this has been asked before, so let me see if there's an answer with an example.
Also see:
- How to remove an array element according to an especific key number?
- Simple task list ordering - how to save it to Firebase Firestore?
- How to update only a single value in an array
- How to update an "array of objects" with Firestore?
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745597047a4635178.html
评论列表(0条)