I am using cloud_firestore for flutter .I want to add onto a map field (userInfo) of a specific document of my firebase database on the press of a button. I do not want to add any other fields, only append more data to the map(userInfo).In this case using this code name is always unique (the userID) of a user.
Firestore.instance.collection("prayerRooms")
.document(docID)
.updateData({
'userInfo.userId': name,
'userInfo.userCount': 2
}
);

This code:
Firestore.instance.collection("prayerRooms")
.document(docID)
.updateData({
'userInfo.userId': name,
'userInfo.userCount': 2
});
will update both the userId and the userCount inside the userInfo map. If you want to add more attribute inside the userInfo map, then you can do:
Firestore.instance.collection("prayerRooms")
.document(docID)
.updateData({
'userInfo.users': "user1",
});
This will add a new attribute inside the map called users.
You can user SetOptions(merge: true) for that
Full code:
Firestore.instance.collection("prayerRooms")
.document(docID)
.set({
'userInfo.userId': name,
'userInfo.userCount': 2
},
SetOptions(merge: true),
);
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