javascript - delete node in firebase - Stack Overflow

been reading docs and other posts but I am unable to remove a node. I am attempting to select the node

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

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

Share Improve this question edited Sep 14, 2016 at 16:18 texas697 asked Sep 14, 2016 at 11:07 texas697texas697 6,46719 gold badges70 silver badges136 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 6

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();
})

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744261491a4565655.html

相关推荐

  • javascript - delete node in firebase - Stack Overflow

    been reading docs and other posts but I am unable to remove a node. I am attempting to select the node

    8天前
    10

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信