0

Here is my firebase enter image description here

I would like to delete the last deed within deeds which happens to be deed id: 1. I would like to do this without specifying anything other than deleting the last deed in deeds.

Here is what I have tried already, but I receive no function errors because i'm returning query type objects.

const deedRef = admin.database().ref('/deeds');
deedRef.limitToLast(1).once("value", (snapshot) => {
    snapshot.val().remove();
})

And

const deedRef = admin.database().ref('/deeds');
deedRef.limitToLast(1).once("value", (snapshot) => {
    snapshot.forEach((deedSnapshot) =>{
         deedSnapshot.remove();
    })
})

And I've tried this

const deedRef = admin.database().ref('/deeds');
deedRef.limitToLast(1).remove();

How can I reference the last deed in deeds and remove it? The last deed will constantly change.

1 Answer 1

3

You were getting close:

const deedRef = admin.database().ref('/deeds');
deedRef.limitToLast(1).once("value", (snapshot) => {
    snapshot.forEach((deedSnapshot) =>{
         deedSnapshot.ref.remove();
    })
})
Sign up to request clarification or add additional context in comments.

3 Comments

It's easiest to remember that you need a Reference to do any write operations. A DataSnapshot is not a Reference, but you can get is reference by calling ref on it.
Frank would you be charged for an operation like this? (i.e. would it count as "downloaded" data as you've queried for it, even if you haven't accessed any data inside that node?)
A DataSnapshot contains a snapshot of the data. That means the data is available in the client, so it has been downloaded, and you will be charged for the bandwidth.

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.