Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

149
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda