0
既存のデータを再開したいが、ファイアベースのクラウド関数がループ処理を行い、合計が無効になる。私の問題の解決策はありますか? はあなたfirebaseクラウド関数の関数実行中にループする
にこの私の画面撮影中
データベース構築 、あなたがon()メソッドを使用して、データベースの参照リスナーを取り付ける
ログ
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;
});