问题
I was using Firebase Database in Web App, and have data like this yet:
How can i delete the entire record having "Apple" in title (marked in picture)?
I wrote the below code but it's not working.
Kindly Help.
var abc = firebase.database().ref('firebase-test');
var key_to_delete = 'Apple';
var query = abc.orderByChild('KISNx87aYigsH3ILp0D').equalTo(key_to_delete);
query.on('child_added', function(snapshot)
{
snapshot.ref.remove();
});
It's not giving me any error in Console.
回答1:
You're ordering/filtering on the wrong property. You have the value of he title
property, so should order on that:
var abc = firebase.database().ref('firebase-test');
var key_to_delete = 'Apple';
var query = abc.orderByChild('title').equalTo(key_to_delete);
query.on('child_added', function(snapshot)
{
snapshot.ref.remove();
});
Alternative, since you know the key of the item you want to delete, you can also delete that item without a query:
var abc = firebase.database().ref('firebase-test');
abc.child("KISNx87aYigsH3ILp0D").remove();
来源:https://stackoverflow.com/questions/46239209/how-to-delete-specific-record-in-firebase-having-specified-title