简体   繁体   中英

How to update individual array element in firebase with iOS Swift?

Here i'm using firestore query to update, insert data. How to upadate dictionary of array value to firebase database.

here is my firestore data structure: 在此处输入图片说明

Right now able to get data of slot1 -> 0th position value in a model class. how can i update value of slot1 0th position of isbooked boolean value alone , without affecting remaining values and other slot .

You can't without reading the entire document, modifying the array data in memory, then updating the entire array field back out do the document. The smallest unit of change in a Firestore array field is an entire field. You can't make smaller changes to individual elements of a field, except those defined by arrayUnion and arrayRemove (which are not compatible with what you're trying to do here).

You can do that by getting the exact id of your structure ..

Database.database().reference().child("SlotName").child(yourAry.key).child(yourAry.key).child("isbooked").setValue(true/false)

Manage your database structure accordingly, its just an example and as user Doug suggested have a look on docs too ..

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM