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

336
Views
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 answers
Answer question

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 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!