I have array of objects, I want to add new object when user enter new data in the array?
Firestore.instance.collection(city).document('Attractions').updateData( "data", FieldValue.arrayUnion(obj) );
This shows error, How can I achieve this with flutter?
When it comes to the official documentation regarding how to update elements in an array in Firestore, it says that: If your document contains an array field, you can use arrayUnion() and arrayRemove() to add and remove elements. arrayUnion() adds elements to an array but only elements not already present.
Right Format is :
Firestore.instance.collection(city).document('Attractions').updateData({"data": FieldValue.arrayUnion(obj)});
updateData
Take Map<String,dynamic>
as data.
In your Code you are having ,
as separator between key - value instead it should be :
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With