【发布时间】:2017-06-17 09:48:09
【问题描述】:
我有以下数据结构:
很遗憾,“days”并未使用以下代码从数据库中删除。
我当前的代码:
const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp(functions.config().firebase);
exports.deleteOldItems = functions.database.ref('/path/to/items/{pushId}') //irrelevant to the question
.onWrite(event => {
var ref = event.data.ref.parent; // reference to the items
var now = Date.now();
var cutoff = now - 2 * 60 * 60 * 1000;
var oldItemsQuery = ref.orderByChild('timestamp').endAt(cutoff);
return oldItemsQuery.once('value', function(snapshot) {
// create a map with all children that need to be removed
var updates = {};
snapshot.forEach(function(child) {
updates[child.key] = null
});
// execute all updates in one go and return the result to end the function
return ref.update(updates);
}).then(function() {;
return functions.database.ref('/days').remove(); // /days doesn't get removed!
});
});
【问题讨论】:
-
你试过没有斜线和子方法吗? functions.database.ref.child('days').remove();
-
@MaduraPradeep 是的,我试过了。它不起作用。解决问题的答案将立即获得赏金!
-
使用 Firebase 类,而不是 Firebase 函数。 ref = new Firebase("myfirebase.com"); ref.child(key).remove();
-
@MaduraPradeep 我只想删除“days”节点。
-
days 不是你的根节点吧?
标签: javascript node.js firebase firebase-realtime-database google-cloud-functions