Home > OS >  How to change the value of a specific field in firebase using flutter?
How to change the value of a specific field in firebase using flutter?

Time:11-13

I want to change the value of "check" for particular values of "attendance"

FirebaseFirestore.instance.collection('students').doc().set({
            'doc':FirebaseFirestore.instance.collection('students').doc(),
            'attendance':title,
            'check':true
          });

Here's the firebase database

What code should I use if I want to change the value of the field of that particular documents.

CodePudding user response:

Use replace set to update Like this:

FirebaseFirestore.instance.collection('students').doc().update({
     
            'check':true
          });

CodePudding user response:

When you call doc() without parameters it generates a reference to a new document.

If you want to update an existing document, you'll need to pass the ID of tht document to the doc(...) call.

FirebaseFirestore.instance.collection('students').doc('rYvghLkro3pYcclwpCPI').update({
  'attendance': 'new title',
});

If you don't know the ID of the document you want to update, you can use a query to look that up based on some value(s) in the document that you do know.

  • Related