I am trying to delete votes from my firebase db table and from my understanding it is an async request that takes time, though my function ends way before than so I get the following error -
Ignoring exception from a finished function
here is my function code -
function continueDeleteFromFirebaseVotesDB(videoId, contestId) {
console.log("before query declaration");
var query = database.ref("votes/" + contestId).orderByKey();
console.log("before foreach loop")
query.once(value)
.then(function (snapshot) {
console.log("inside foreach loop")
if (!snapshot.exists) {
console.log("votes db snapshot does not exist");
return;
}
snapshot.forEach(function (childSnapshot) {
//var key = childSnapshot.key;
// childData will be the actual contents of the child
var childData = childSnapshot.val();
if (childData.video_id === contestId) {
childSnapshot.ref.remove();
console.log("removed vote - " + JSON.stringify(childSnapshot))
continueDeleteFromFirebaseVideosDB(videoId)
}
});
return query;
})
.then(function (data) {
console.log(JSON.stringify(data));
})
}
What am I missing in order to make my function async and wait for the result?