0
我試圖Firebase雲功能在我的應用程序中使用此代碼在創建2小時後刪除數據。檢測一個裁判的更改並寫入另一個Firebase雲
exports.deleteOldItems = functions.database.ref('/Rooms/{pushId}')
.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('timestampCreated/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);
});
});
This Works。現在我想寫另一個參考(例如:/用戶/ {用戶ID} /)每次刪除數據。問候
什麼是你有執行該要求的問題? –
@FrankvanPuffelen嗨弗蘭克,問題是,我不知道如何寫承諾,因爲我看到的例子總是在上面所述的相同參考文獻中進行了修改(exports.deleteOldItems = functions.database.ref('/ Rooms/{pushId}')例如)。謝謝 –