我有一個Firebase數據庫函數的問題。該documentation contains the following minimal example與交易數據的工作:Firebase類型錯誤:ref.transaction不是函數
var upvotesRef = db.ref("server/saving-data/fireblog/posts/-JRHTHaIs-jNPLXOQivY/upvotes");
upvotesRef.transaction(function (current_value) {
return (current_value || 0) + 1;
});
現在,我的火力點的數據庫結構如下所示
/game-results
/RaUALJvTZVea5y6h1lzqGJPMpuI3
/distance
/score
/timestamp
/3ItAqKHL0XRUOum2Ajdz9hHQxMs1
/distance
/score
/timestamp
/statistics
/total-distance
/total-score
而且我想分數和距離總結到總。我使用下面的函數,這裏total-distance
:
const functions = require('firebase-functions');
exports.updateTotalDistance = functions.database.ref('/game-results/{userId}/distance')
.onWrite(event => {
const newDistance = event.data.val();
const distanceRef = functions.database.ref('/statistics/total-distance')
return distanceRef.transaction(function(currentDistance) {
console.log('currentDistance', currentDistance);
return (currentDistance || 0) + newDistance;
});
});
不過,我不能換我周圍爲什麼我得到的火力功能記錄以下錯誤頭:
TypeError: distanceRef.transaction is not a function
at exports.updateTotalDistance.functions.database.ref.onWrite.event (/user_code/index.js:19:22)
at /user_code/node_modules/firebase-functions/lib/cloud-functions.js:35:20
at process._tickDomainCallback (internal/process/next_tick.js:129:7)
爲什麼數據庫引用不允許我寫交易數據?我想要做的就是總結所有的分數和距離。