本文介绍了使用Firebase云功能从Firebase数据库中删除节点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我正在尝试制作Firebase云端功能,以便从Firebase数据库中删除一个节点。日志消息显示函数执行ok,但似乎并没有从数据库中删除任何元素。我在如何删除Firebase中的数据? a> 这里是代码片段 const functions = require('firebase-functions'); const admin = require('firebase-admin'); admin.initializeApp(functions.config()。firebase); //路径被定义为要删除的值, console.log(删除元素+路径); var ref = admin.database()。ref(/) ref.orderByValue()。equalTo(path).on('child_added',function(snapshot){ console .log(Snapshot.ref =+ snapshot.ref); snapshot.ref.remove(); return; });另外,在上面的代码中,删除元素path_value确实出现在日志中,但是快照。 ref = ...不显示。 我没有足够的信用额度来嵌入图像,所以这是一个链接到我的数据库 Firebase数据库的结构 解决方案我认为选择是错误的。仔细检查ref.orderByValue()。equalTo(path)是否真的等于某事。 $ b ref.once('value' ) .then(function(dataSnapshot){ //处理读取数据。}); https://firebase.google.com/docs/reference/admin/node/admin.database.Reference var adaRef = admin.database()。ref('users / ada'); adaRef.remove() .then(function(){ console.log(Remove succeeded。)}) .catch(function(error ){ console.log(Remove failed:+ error.message)}); I'm trying to make a firebase cloud function to delete a node from Firebase Database. The log messages show that the function executed "ok" but it doesn't seem to remove any element from the database. I wrote the function taking help from the accepted answer in How to delete data in Firebase?Here is the snippet of the codeconst functions = require('firebase-functions');const admin = require('firebase-admin');admin.initializeApp(functions.config().firebase);//path is defined as the value to be deleted,console.log("Deleting element " + path);var ref = admin.database().ref("/")ref.orderByValue().equalTo(path).on('child_added', function(snapshot) { console.log("Snapshot.ref = " + snapshot.ref); snapshot.ref.remove(); return;});Also, in the above code, "Deleting element path_value" does show up in the log but Snapshot.ref = ... doesn't show up.I don't have enough credits to embed images yet so here is a link to my databaseStructure of Firebase Database 解决方案 I think the selection is wrong. Double check that ref.orderByValue().equalTo(path) is actually equal to something.ref.once('value') .then(function(dataSnapshot) { // handle read data. });https://firebase.google.com/docs/reference/admin/node/admin.database.Referencevar adaRef = admin.database().ref('users/ada');adaRef.remove() .then(function() { console.log("Remove succeeded.") }) .catch(function(error) { console.log("Remove failed: " + error.message) }); 这篇关于使用Firebase云功能从Firebase数据库中删除节点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 08-24 04:25