Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Firestore: How to update specific field of document?

How do I access and update a specific field in angular firestore: enter image description here

like image 678
Rogerto Avatar asked Dec 11 '22 04:12

Rogerto


2 Answers

It should be pretty easy task. You can use update function and pass the field name and value to update.

ex :

this.db.doc(`options/${id}`).update({rating:$rating}); //<-- $rating is dynamic
like image 91
Sunil Singh Avatar answered Jan 24 '23 08:01

Sunil Singh


Is very simple (.collection) to declare the collection that u want to change (.doc) to specify the id of the document that u want to update and the in (.update) just put the update field that u want change it

 constructor(private db: AngularFirestore) {}
 this.db
  .collection('options')
  .doc('/' + 'mzx....')
  .update({rating: value})
  .then(() => {
    console.log('done');
  })
  .catch(function(error) {
   console.error('Error writing document: ', error);
  });
like image 34
Sofien Abdeddaim Avatar answered Jan 24 '23 08:01

Sofien Abdeddaim