Firebase V9 Firestore UPDATE Document Data Using updateDoc()
3 min readAug 8, 2022
There are two methods you can use to update an existing document in Firebase Version 9 Cloud Firestore.
setDoc()
updateDoc() → you’re here
Using updateDoc(), you can only update the document field of an existing document in the Firestore Database which can be:
Add A New Document Field Using updateDoc()
Here is a sample document inside the cities collection from the Cloud Firestore Database.
In order to update an existing document using the updateDoc()method, we need three methods:
- getDatabase() → where we want to update a document.
- doc() → where we’ll be passing references of database, collection, and ID of a document that we want to update one of its fields.
- updateDoc() → where we actually pass new data that we want to replace along with the doc() method.