【发布时间】:2018-06-01 20:00:27
【问题描述】:
我已经部署了一个 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) 在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) 在下一个(本机) 在 /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 在 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
}
有什么帮助吗?
【问题讨论】:
-
嗯,我没有解决这个问题的办法,但我可以告诉你的是,你并不孤单。'今天我想执行一个云功能,效果很好昨天,但今天我遇到了和你一样的错误,重新部署或更改代码都没有解决这个问题。我有几个函数,除了带有数据库触发器的函数外,所有函数都可以正常工作。在 http 触发函数中进行读取和写入不会出现任何错误。所以我认为这与我们的代码无关,而是与 Firebase/Firestore 本身有关。
-
Github 上的类似问题:github.com/firebase/firebase-functions/issues/149
-
嘿阿尔贝托。 Firebaser在这里。目前尚不清楚是什么原因造成的,但我们的工程师怀疑这可能与您的依赖关系有关。您可以编辑您的问题以包含您的
package.json吗? -
添加 package.json 内容编辑
标签: javascript firebase google-cloud-functions google-cloud-firestore