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