我想制作现有数据的简历,但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;
});