Firebase V9 Firestore DELETE Document Using deleteDoc()
Learn how to delete a document from a collection in Firebase version 9 Cloud Firestore using the deleteDoc() method.
- Delete A Document from a collection → you’re here
- Delete A Field from a document
Here is the sample document from the cities collection in Cloud Firestore Database that I want to delete.
First, import Firestore Database and de-structure the three methods we need:
- getFirestore()
- doc()
- deleteDoc()
import { getFirestore, doc, deleteDoc } from "firebase/firestore";
Initialize Firestore Database and assign it to the constant db.
const db = getFirestore();
The deleteDoc() method takes one method as an argument to perform the delete operation which is
- doc()
The doc() method takes three arguments which are:
- database → db
- collection name → cities
- document ID → yftq9RGp4jWNSyBZ1D6L (ID of a document…