I'm trying to make a firebase cloud function to delete a node from Firebase Database. The log messages show that the function executed "ok" but it doesn't seem to remove any element from the database. I wrote the function taking help from the accepted answer in How to delete data in Firebase? Here is the snippet of the code
const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp(functions.config().firebase);
//path is defined as the value to be deleted,
console.log("Deleting element " + path);
var ref = admin.database().ref("/")
ref.orderByValue().equalTo(path).on('child_added', function(snapshot) {
console.log("Snapshot.ref = " + snapshot.ref);
snapshot.ref.remove();
return;
});
Also, in the above code, "Deleting element path_value" does show up in the log but Snapshot.ref = ... doesn't show up.
I don't have enough credits to embed images yet so here is a link to my database Structure of Firebase Database