![](/img/trans.png)
[英]Fill array in Firebase Cloud Functions from Firebase database
[英]Deleting a node from firebase database using firebase cloud functions
我正在尝试使用firebase云功能从Firebase数据库中删除节点。 日志消息显示该函数执行“ok”但似乎没有从数据库中删除任何元素。 我从如何删除Firebase中的数据中接受的答案中写了这个函数? 这是代码的片段
const 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;
});
此外,在上面的代码中,“删除元素path_value”确实显示在日志中,但Snapshot.ref = ...没有显示。
我认为选择是错误的。 仔细检查ref.orderByValue()。equalTo(path)实际上是等于某事。
ref.once('value')
.then(function(dataSnapshot) {
// handle read data.
});
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)
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.