Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

150
Views
How delete firestore document

I use this code below and run well in Firebase RealTime Database:

const onDelete = (id) => {
  if (
    window.confirm("Are you sure that you wanted to delete the contact ?")
  ) {
    Db.child(`contacts/${id}`).remove((err) => {
      if (err) {
        alert(err);
      } else {
        alert("Contact Deleted Successfully");
        console.timeStamp(id);
      }
    });
  }
};

Now I create another database in Firebase Firestore but cannot delete.

const onDelete = (id) => {
  if (window.confirm("Are you sure that you wanted to delete contact ?")) {
    firebase
      .firestore()
      .collection("contacts")
      .doc(`${id}`)
      .delete()
      .then(() => {
        console.log("Document successfully deleted!");
      })
      .catch((error) => {
        console.error("Error removing document: ", error);
      });
  }
};
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

There's no difference in the databases here: in both cases you have to specify the full path to the data to be deleted.

If you can somehow specify line numbers for the Realtime Database, most likely you've used those line numbers as keys in your database. And if you can't do the same on Firestore, it's likely you didn't use the line numbers as document IDs there. If that is indeed the case, you'll need to either maintain a mapping from line numbers to document IDs, or use the line numbers for the document IDs in Firestore too.

about 4 years ago · Juan Pablo Isaza Report

0

const onDelete = async (id) => {
    if (
      window.confirm("Are you sure that you wanted to delete the contact ?")
    ) {
      firebase
        .firestore()
        .collection("contacts")
        .get()
        .then(async (querySnapshot) => {
          await deleteDoc(doc(db, "contacts", querySnapshot.docs[id].id));
          alert("Contact Deleted Successfully");
        });
    }
};
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!