Firebase query and delete data in javascript

廉价感情. 提交于 2021-01-29 14:22:10

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!