Ask Your Question
3

How can I update a single field in Firestore?

asked 2022-10-03 11:00:00 +0000

nofretete gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
3

answered 2021-07-27 04:00:00 +0000

huitzilopochtli gravatar image

To update a single field in Firestore, you can use the update() method on the document reference with the new value. Here is an example:

// Get a reference to the document you want to update
const docRef = db.collection('cities').doc('LA');

// Update the population field with a new value
docRef.update({ population: 4000000 })
  .then(() => {
    console.log('Document updated successfully');
  })
  .catch((error) => {
    console.error('Error updating document', error);
  });

This code updates the population field of the document with ID LA in the cities collection to the new value of 4000000. You can replace the field name and value with the ones you want to update.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2022-10-03 11:00:00 +0000

Seen: 18 times

Last updated: Jul 27 '21