Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

151
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda