简体   繁体   English

使用firebase云功能从firebase数据库中删除节点

[英]Deleting a node from firebase database using firebase cloud functions

I'm trying to make a firebase cloud function to delete a node from Firebase Database. 我正在尝试使用firebase云功能从Firebase数据库中删除节点。 The log messages show that the function executed "ok" but it doesn't seem to remove any element from the database. 日志消息显示该函数执行“ok”但似乎没有从数据库中删除任何元素。 I wrote the function taking help from the accepted answer in How to delete data in Firebase? 我从如何删除Firebase中的数据中接受的答案中写了这个函数 Here is the snippet of the code 这是代码的片段

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;
});

Also, in the above code, "Deleting element path_value" does show up in the log but Snapshot.ref = ... doesn't show up. 此外,在上面的代码中,“删除元素path_value”确实显示在日志中,但Snapshot.ref = ...没有显示。

I don't have enough credits to embed images yet so here is a link to my database Structure of Firebase Database 我没有足够的学分来嵌入图像,所以这里是我的数据库Firebase数据库结构的链接

I think the selection is wrong. 我认为选择是错误的。 Double check that ref.orderByValue().equalTo(path) is actually equal to something. 仔细检查ref.orderByValue()。equalTo(path)实际上是等于某事。

ref.once('value')
  .then(function(dataSnapshot) {
    // handle read data.
  });

https://firebase.google.com/docs/reference/admin/node/admin.database.Reference 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.

相关问题 从Firebase数据库填充Firebase Cloud Functions中的数组 - Fill array in Firebase Cloud Functions from Firebase database 如何使用 firebase 云函数从 firebase-realtime-database 中获取数据? - How to fetch data from firebase-realtime-database using firebase cloud functions? 如何使用Firebase云功能从Firebase数据库检索子节点的键值? - How to retrieve key value of child node from firebase database using firebase cloud function? Firebase 实时数据库中的云函数 - Cloud Functions in Firebase Realtime Database Firebase Cloud Functions未写入数据库 - Firebase Cloud Functions not writing in database 使用 Firebase 云函数从 firebase 发送推送通知 - Send push notification From firebase by using Firebase cloud Functions 与 firebase 云函数中的 firebase firestore 交互 - Interacting with firebase firestore from firebase cloud functions 如何使用云函数从我的 Firebase 实时数据库中 database.ref 正在侦听的节点内部获取数据? - How can I fetch data from inside a node which the database.ref is listening to in my Firebase real-time database using cloud functions? 使用Firebase Cloud Functions将值从一个节点复制到多个其他节点 - Copy value from one node to multiple other nodes using Firebase Cloud Functions Firebase Cloud Functions可立即删除节点,而不是2小时后删除 - Firebase Cloud Functions is deleting nodes instantly instead of deleting after 2 hours
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM