4

i am doing some work with flutter and firebase, so i can't figure out how add new elements to an existing document who has an existing map with some created fields so.. the map for example is this

'Users':{uid0:{'Name':{'userName0'},uid1:{'Name':{'userName1'}}

An this is my actual code.

Firestore.instance.collection('on_going_matches').where('userSlot',isGreaterThan: 0).snapshots().listen(
          (data) => {
              Firestore.instance.runTransaction((transaction) async {
                await transaction.update(Firestore.instance.collection("on_going_matches").document(data.documents[0].documentID), {
                  'users': {uid:{'Name':name}},
                  'userSlot': data.documents[0]['userSlot'] - 1
                }
                );
              })
              });

I have another question too, what i can do when "where" condition "where('userSlot',isGreaterThan: 0)" is not found, how i can use this like an if/else statement so, if Firestore query is not found, do a thing.

3
  • to update an existing document: myDocument.setData(myMap, merge: true); Commented Jul 8, 2019 at 6:11
  • Yeah, thanks, i was trying to do this with transactions... but i realized that i can't Commented Jul 11, 2019 at 19:32
  • Nice to hear that. Please, upvote my awnser :) Commented Jul 12, 2019 at 20:06

1 Answer 1

4

To update an existing document: myDocument.setData(myMap, merge: true);

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.