Reputation: 323
I am using map inside array in firestore document. The problem is that when i am adding maps with new values then instead of increasing the size of array it is replacing new map with current map. My code is look like this:
Map<String, dynamic> map = {'name': "Asad"};
RaisedButton(
child: Text("press me"),
onPressed: () {
Firestore.instance.collection('Shops').document('2').setData({
'name': 'Ali',
'id': '3',
'array': FieldValue.arrayUnion([map])
});
},
),
And my firestore db looks like this:
How to increase the size of array or you can say how to add new element inside array instead of replacing it.Thanks in advance.
Upvotes: 0
Views: 352
Reputation: 317467
If you want to update a document instead of overwriting its content, you should use updateData() instead of setData(). Either that, or pass {merge: true}
to setData() as the second argument.
Upvotes: 2