问题
Here is my firebase
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:
You were getting close:
const deedRef = admin.database().ref('/deeds');
deedRef.limitToLast(1).once("value", (snapshot) => {
snapshot.forEach((deedSnapshot) =>{
deedSnapshot.ref.remove();
})
})
来源:https://stackoverflow.com/questions/51034667/firebase-query-and-delete-data-in-javascript