With Firebase Version 9 (Feb, 2022 Update):
If there is the collection "users" having one document(dWE72sOcV1CRuA0ngRt5) with the fields "name", "age" and "sex" as shown below:
users > dWE72sOcV1CRuA0ngRt5 > name: "John",
age: 21,
sex: "Male"
You can delete the field "age" with this code below:
import { doc, updateDoc, deleteField } from "firebase/firestore";
const userRef = doc(db, "users/dWE72sOcV1CRuA0ngRt5");
// Remove "age" field from the document
await updateDoc(userRef, {
"age": deleteField()
});
users > dWE72sOcV1CRuA0ngRt5 > name: "John",
sex: "Male"
You can delete multiple fields "age" and "sex" with this code below:
import { doc, updateDoc, deleteField } from "firebase/firestore";
const userRef = doc(db, "users/dWE72sOcV1CRuA0ngRt5");
// Remove "age" and "sex" fields from the document
await updateDoc(userRef, {
"age": deleteField(),
"sex": deleteField()
});
users > dWE72sOcV1CRuA0ngRt5 > name: "John"