Firebase calling .remove() on ref is removing all parents

后端 未结 1 754
醉梦人生
醉梦人生 2020-12-22 05:14

In the following code, after processing the data returned in the snapshot, I am seeking to remove the record in question. When I call remove on my reference with the key of

相关标签:
1条回答
  • 2020-12-22 05:56

    It's hard to be certain without seeing your JSON structure (hint: add it to your question as text), but I think you may be mistaking how Firebase operates.

    Firebase stores values at locations identified by paths. When you store a value at a location, the path is automatically created. When you remove the last value from a location, the path is automatically removed.

    Aside from that, this code is somewhat more idiomatic:

    fbRef.on('value', function (snap) {
      if (snap.exists()) {
        snap.forEach(function(msgSnap) {          
          var msg = msgSnap.val();
          messenger(msg, function (msgErr, msgData) {
            if (!msgErr) {
              msgSnap.ref().remove();
            }
            else {
              console.log(msgErr);
            }
          });
        });
      }
    });
    
    0 讨论(0)
提交回复
热议问题