firestore delete code example

Example 1: how to delete document firestore database

db.collection("cities").doc("DC").delete().then(() => {
    console.log("Document successfully deleted!");
}).catch((error) => {
    console.error("Error removing document: ", error);
});

Example 2: how to delete firebase collection

this.db
  .collection('cart')
  .get()
  .toPromise()
  .then((querySnapshot) => {
  querySnapshot.forEach((doc) => {
    doc.ref.delete();
  });
});

Example 3: firestore javascript delete document

// define document location (Collection Name > Document Name > Collection Name >)
var docRef = Firebase.firestore().collection("Rooms").doc("bsYNIwEkjP237Ela6fUp").collection("Messages");

// delete the document
docRef.doc("lKjNIwEkjP537Ela6fhJ").delete();

Example 4: firestore delete document by id

const res = await db.collection('cities').doc('DC').delete();