无法从Firestore值解码类型

问题描述 投票:5回答:1

我已经部署了一个Cloud Firebase功能来更新一些聚合数据,但我得到了

aggregateReceivedRatings:错误:无法从Firestore值解码类型:{“integerValue”:“3”}在DocumentSnapshot._decodeValue(/user_code/node_modules/firebase-admin/node_modules/@google-cloud/firestore/src/document.js:464 :15)在exports.aggregateReceivedRatings.functions.firestore.document.onWrite.event上的DocumentSnapshot.get(/user_code/node_modules/firebase-admin/node_modules/@google-cloud/firestore/src/document.js:372:17) (/user_code/lib/index.js:9:32)在Object。 (/user_code/node_modules/firebase-functions/lib/cloud-functions.js:59:27)at next(native)atuser_code/node_modules/firebase-functions/lib/cloud-functions.js:28:71 at __awaiter (/user_code/node_modules/firebase-functions/lib/cloud-functions.js:24:12)位于/ var /的cloudFunction(/user_code/node_modules/firebase-functions/lib/cloud-functions.js:53:36) 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
}

有帮助吗?

javascript firebase google-cloud-functions google-cloud-firestore
1个回答
2
投票

只需将firebase admin更新为5.5.1即可。它对我有用。只需使用命令行:npm install --save firebase-admin@^5.5.1

© www.soinside.com 2019 - 2024. All rights reserved.