0

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");
});
1
  • Please edit the question to show the relevant output of the Functions console log. There will certainly be something there that indicates the problem. Commented Jun 25, 2018 at 6:36

1 Answer 1

2

The problem has nothing to do with Cloud Functions.

deedRef.limitToLast(1) returns a Query type object. Query doesn't have a method called remove(). Therefore, your code will fail at runtime with a message to that effect.

If you want to delete some data from Realtime Database, you're going to need a Reference type object, which has a remove() method. This will remove everything at the location of the reference.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.