4

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 } ); 

Here is the database in question

3 Answers 3

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.

Sign up to request clarification or add additional context in comments.

5 Comments

Oh,no don't want to add another attribute, I want to add more data into the userId and userCount of the map. So every time I press the button with a different user, it should add that user's data into the userCount and userId field.It should keep the previous data , not overwrite it or update it.
every time you press the button with a different user, you should create a different document and not add it to the map, the max document size is 1mb, if every time a different user presses the button and you add to the map then the application wont scale
Yes, I have read it. My app (at least starting off) will be limited to only a few users(30 or less).
Yes still u need to do it correctly from the beginning, each user should have thier own document
1

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), ); 

Comments

0

2023:

 FirebaseFirestore db = FirebaseFirestore.instance; db.collection("collection") .doc("DOC-ID") .update({ 'userInfo.users': "user1" }); 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.