I have a Firebase cloud function. Everything works as expected within the helloWorld function except the line deedRef.limitToLast(1).remove(); I also tried to do .ref(/deeds/${deedID}).remove() is there a reason why I can't remove data from firebase within cloud functions? The output from the http request is "Error: could not handle the request".
const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp();
const deedRef = admin.database().ref('/deeds');
const oldDeedRef = admin.database().ref('/oldDeeds');
exports.helloWorld = functions.https.onRequest((req, res) => {
deedRef.limitToLast(1).once("value", (snapshot) => {
snapshot.forEach((deedSnapshot) =>{
let deedID = deedSnapshot.val().id;
let text = deedSnapshot.val().message;
oldDeedRef.push({
id: deedID,
message: text
})
})
})
deedRef.limitToLast(1).remove();
res.send("Congrats For running the function");
});