[英]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.