Reputation: 1017
The following transaction completely replaces the data in a Firestore Map when run:
DocumentSnapshot docSnapshot = await tx.get(docRef); // doc Snapshot
if (docSnapshot.exists) {
await tx.update(
docRef,
<String, dynamic>{
'Users': {
'user.uid': {'name': user.displayName, 'date': DateTime.now()},
}
},
);
What would be the correct way to add to a map instead of replacing the existing data, the same way FieldValue.arrayUnion works?
Upvotes: 1
Views: 160
Reputation: 1708
Since you already fetched the data you could take the map out from the snapshot, replace the data there and call the update with the altered map.
Upvotes: 1