How To Delete A Specific Field In Firebase Firestore Document
If you want to delete a specific field from a firebase document, use the FieldValue.delete()
method when you update a document.
The implementation will vary depending on what platform or language you use.
For the web it's generally this way:
1 2 3 |
|
But if you are using a NodeJs
environment such as firebase functions: First you need to import firebase-admin
to your nodejs app.
1 |
|
Next you get to get the firestore.FieldValue
. To do so, simply define a new variable: const fieldValue = admin.firestore.FieldValue;
With that we can use the fieldValue
variable to get access to our firebase firestore document fields and delete them in an update
operation call.
1 2 3 4 |
|
And here is the complete code for this:
1 2 3 4 5 6 |
|
For more, go here https://firebase.google.com/docs/firestore/manage-data/delete-data#fields