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

337
Visualizações
how to delete firebase realtime database child node with key?

When I try to run the code below I get an error and I'm not sure why.

confirmDelete(e) {
  const db = getDatabase();
  db.ref("/ships/" + e.target.id).remove();
},

If I log the e.target.id I get the exact same as the shipKey in the code below.

Here's an example of what that database looks like:

{
  "ships": {
    "-N43Q4E2ruMpyfaIHGDK": {
      "date": "2022-08-06T18:00",
      "name": "ORANGE OCEAN",
      "shipKey": "-N43Q4E2ruMpyfaIHGDK"
    }
  }
}
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

It seems you are using Firebase Modular SDK (V9.0.0+) where both ref() and remove() are top-level functions. Try refactoring the code as shown below:

// import the functions
import { getDatabase, ref, remove } from "firebase/database";

confirmDelete(e) {
  const db = getDatabase();
 
  // create DatabaseReference
  const dbRef = ref(db, "/ships/" + e.target.id);

  remove(dbRef).then(() => console.log("Deleted"))
},

Checkout the documentation to learn more about the new syntax.

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