Taneda
Taneda

Reputation: 13

How to delete a specific data in Firebase Realtime Database?

This is my code and it doesn't work it says that dbRef.remove() is not a function.

DeleteData1.addEventListener('click',(e)=>{

   var deleteCrop1 = document.getElementById('deleteCrop').value;

   const dbRef = ref (database, 'Crops/'+deleteCrop1);

if(document.getElementById('deleteCrop').value == ''){
   alert("Fields cannot be empty");
}else{
   dbRef.remove();
   alert("Data removed successfully")''
}


});

I tried using the docs in firebase but my code just doesn't work.

Upvotes: 1

Views: 611

Answers (1)

Doug Stevenson
Doug Stevenson

Reputation: 317467

With the v9 SDK, there is no longer a remove() method on a DatabaseReference object. Instead, you should use the remove() function and pass the reference to it.

remove(dbRef)
    .then(...)
    .catch(...)

Upvotes: 1

Related Questions