delete node in firebase

落花浮王杯 提交于 2021-02-08 01:33:49

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!