我已部署了Cloud Firebase功能来更新某些汇总数据,但我已经
aggregateReceivedRatings:错误:无法从Firestore值解码类型:{" integerValue":" 3"} 在DocumentSnapshot._decodeValue(/user_code/node_modules/firebase-admin/node_modules/@google-cloud/firestore/src/document.js:464:15) 在DocumentSnapshot.get(/user_code/node_modules/firebase-admin/node_modules/@google-cloud/firestore/src/document.js:372:17) at exports.aggregateReceivedRatings.functions.firestore.document.onWrite.event(/user_code/lib/index.js:9:32) 在对象。 (/user_code/node_modules/firebase-functions/lib/cloud-functions.js:59:27) 在下一个(本地) at /user_code/node_modules/firebase-functions/lib/cloud-functions.js:28:71 在__awaiter(/user_code/node_modules/firebase-functions/lib/cloud-functions.js:24:12) 在cloudFunction(/user_code/node_modules/firebase-functions/lib/cloud-functions.js:53:36) 在/var/tmp/worker/worker.js:695:26 at process._tickDomainCallback(internal / process / next_tick.js:135:7)
该功能非常类似于Firestore解决方案部分中针对聚合查询所示的功能:
exports.aggregateReceivedRatings = functions.firestore.document('users/{userId}/feedbacks_received/{ratingId}')
.onWrite(event => {
var ratingVal = event.data.get('rating');
const db = admin.firestore();
var restRef = db.collection('users').document(event.params.userId);
return db.transaction(transaction => {
return transaction.get(restRef).then(restDoc => {
var newNumRatings = restDoc.data('received_feedbacks').tot + 1;
var newSum = restDoc.data('received_feedbacks').sum + ratingVal;
return transaction.update(restRef, {
sum: newSum,
tot: newNumRatings
});
});
});
});
评级值为整数3。
我也跑
npm install firebase-functions @ latest firebase-admin @ latest --save
并重新部署,但没有运气。
我的package.json包含以下内容:
{
"name": "functions",
"scripts": {
"build": "./node_modules/.bin/tslint -p tslint.json && ./node_modules/.bin/tsc",
"serve": "npm run build && firebase serve --only functions",
"shell": "npm run build && firebase experimental:functions:shell",
"start": "npm run shell",
"deploy": "firebase deploy --only functions",
"logs": "firebase functions:log"
},
"main": "lib/index.js",
"dependencies": {
"firebase-admin": "~5.4.2",
"firebase-functions": "^0.7.1"
},
"devDependencies": {
"tslint": "^5.8.0",
"typescript": "^2.5.3"
},
"private": true
}
任何帮助?
答案 0 :(得分:2)
只需将firebase admin更新为5.5.1。它对我有用。只需使用命令行: npm install --save firebase-admin@^5.5.1