So, I'm using this firebase-admin library here. I read the docs from Firebase here. But I can't find the section how to remove the data with firebase-admin.
I do something like this, but it doesn't work:
router.get('/delete_category', function(req, res, next) {
var key = req.query.item;
let del_ref = admin.database().ref("product/" + key);
del_ref.remove()
});
Can you guys help me on how to delete the data from my firebase database with firebase-admin? Thanks in advance
Notes: I am using NodeJS with Express Framework and Handlebars
Your code looks correct. The remove()
method is what you want to use. You probably just need to add a completion listener to ensure that the remove()
call was successful:
router.get('/delete_category', function(req, res, next) {
var key = req.query.item;
let del_ref = admin.database().ref("product/" + key);
del_ref.remove()
.then(function() {
res.send({ status: 'ok' });
})
.catch(function(error) {
console.log('Error deleting data:', error);
res.send({ status: 'error', error: error });
});
});
SOLVED: Finally I found the answer
I made mistake in the references here
let del_ref = admin.database().ref("product/" + key);
It should be read the category ref like this:
let del_ref = admin.database().ref("category/" + key);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With