问题
been reading docs and other posts but I am unable to remove a node. I am attempting to select the node by a value.
var eventContactsRef = firebase.database().ref('events-contacts');
eventContactsRef.orderByChild('eventContactId').equalTo(eventContactId);
then call the remove method on the result
eventContactsRef.remove(function (error) {
console.log(error);
});
nothing happens except a null error value. I am using the latest firebase, most examples are for older versions so I am unsure if I need to get the key and then attempt to delete with that as a reference?
This is the first time using firebase so I am not sure if I have saved the data correctly. here is code to save.
var key = firebase.database().ref().child('event-contacts').push().key;
var url = firebase.database().ref('/event-contacts/' + key);
url.set(eventContacts);
and screenshot
回答1:
You cannot remove a query itself. You can only remove the results that match a query.
var eventContactsRef = firebase.database().ref('events-contacts');
var query = eventContactsRef.orderByChild('eventContactId').equalTo(eventContactId);
query.on('child_added', function(snapshot) {
snapshot.ref.remove();
})
来源:https://stackoverflow.com/questions/39488911/delete-node-in-firebase