【发布时间】:2017-08-03 05:38:19
【问题描述】:
我想恢复现有数据,但 Firebase 云函数会执行循环,因此我所做的总和无效。我的问题有解决方案吗? 谢谢
这是我的屏幕截图
数据库建设 ,
日志
const functions = require('firebase-functions');
const admin = require("firebase-admin");
admin.initializeApp(functions.config().firebase);
var db = admin.database();
exports.makePurchaseSummaryAdd = functions.database.ref('/invoice_data/{pushIdInvoice}/item/{pushIdItem}')
.onCreate(event => {
var name = event.data.child('itemName').val();
var quantity = event.data.child('quantity').val();
var ref = db.ref('/invoice_data/' + event.params.pushIdInvoice + '/idUser');
ref.on("value", function(snapshot) {
var refUser = db.ref('/user_data/' + snapshot.val() + '/purchaseSummary/' + name.toUpperCase());
refUser.on("value", function(snapshotUser) {
if (snapshotUser.exists()){
console.log('Ada Data');
var count = snapshotUser.val();
var newCount = quantity + count;
refUser.set(newCount);
console.log('create', count, newCount, name.toUpperCase());
}
else {
console.log('Tidak Ada Data');
}
}, function (errorObject) {
console.log("The read failed: " + errorObject.code);
});
}, function (errorObject) {
console.log("The read failed: " + errorObject.code);
});
return true;
});
【问题讨论】:
标签: node.js firebase firebase-realtime-database google-cloud-functions