How can i update or delete an object in an array in firestore with swift?

1,638 views
Skip to first unread message

azim vaziri

unread,
May 13, 2019, 7:32:36 PM5/13/19
to Firebase Google Group
I want to update a field of an object that the object is into an array in firestore database with swift 4. These two function (arrayUnion() and arrayRemove() ) are not working for me.
Please help me.

Kato Richardson

unread,
May 14, 2019, 2:26:27 PM5/14/19
to Firebase Google Group
Azim, it's going to be hard to guess what's going wrong without more context. Could you provide some code and sample data that reproduces the error, along with detailed logging and errors you're encountering? See this link for more help on asking effective troubleshooting questions: http://stackoverflow.com/help/mcve

--
You received this message because you are subscribed to the Google Groups "Firebase Google Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to firebase-tal...@googlegroups.com.
To post to this group, send email to fireba...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/firebase-talk/22906216-7da1-4195-8dda-21013f9eac9c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


--

Kato Richardson | Developer Programs Eng | kato...@google.com | 775-235-8398

Nate Park

unread,
Mar 13, 2020, 7:55:49 PM3/13/20
to Firebase Google Group
I hope this thread is still available. I actually have the same question as Azim, so I'd like to add some more details to it (Swift & Firestore). 

My Cloud Firestore's chat collection has a nested array called 'messages'.
Chat collection: [
     
"chatMember": ["member1", "member2"],
     
"createdAt" : Date().timeIntervalSince1970,
     
"meesages" : []
]
My goal is to append objects, aka Dictionary ([String: Any]) into the messages array.

Firestore document <Link> introduces FieldValue.arrayUnion() & .arrayRemove() to update elements in an array.

But this doesn't work on Swift with an error saying, "Contextual type '[Any]' cannot be used with dictionary literal".

I saw a Youtube video that uses the .arrayUnion method with Angular and it works perfectly, but Swift doesn't work when I try to do the same. 

I hope my explanation clears your confusion and I very much look forward to hearing back from you Kato.

Thank you in advance for your help.


On Tuesday, May 14, 2019 at 2:26:27 PM UTC-4, Kato Richardson wrote:
Azim, it's going to be hard to guess what's going wrong without more context. Could you provide some code and sample data that reproduces the error, along with detailed logging and errors you're encountering? See this link for more help on asking effective troubleshooting questions: http://stackoverflow.com/help/mcve

From: azim vaziri <azimv...@gmail.com>
Date: Mon, May 13, 2019 at 4:32 PM
To: Firebase Google Group

I want to update a field of an object that the object is into an array in firestore database with swift 4. These two function (arrayUnion() and arrayRemove() ) are not working for me.
Please help me.

--
You received this message because you are subscribed to the Google Groups "Firebase Google Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to fireba...@googlegroups.com.

To post to this group, send email to fireba...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/firebase-talk/22906216-7da1-4195-8dda-21013f9eac9c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


--

Kato Richardson | Developer Programs Eng | kato...@google.com | 775-235-8398

Reply all
Reply to author
Forward
0 new messages