I deployed the Cloud Firebase feature to update some aggregate data, but I get
aggregateReceivedRatings: Error: Unable to decode type from Firestore value: {"integerValue": "3"} in DocumentSnapshot._decodeValue (/ user_code / node_modules/firebase-admin/node_modules/@google-cloud/firestore/src/document.js: 464 : 15) at DocumentSnapshot.get (/user_code/node_modules/firebase-admin/node_modules/@google-cloud/firestore/src/document.jshaps72:17) at export.aggregateReceivedRatings.functions.firestore.document.onWrite.event (/user_code/lib/index.js:9:32) in the object. (/user_code/node_modules/firebase-functions/lib/cloud-functions.js:59:27) on the next (native) on / user _code / node_modules / firebase-functions / lib / cloud-functions.js: 28: 71 on __awaiter (/user_code/node_modules/firebase-functions/lib/cloud-functions.js:24:12) in cloudFunction (/user_code/node_modules/firebase-functions/lib/cloud-functions.js:53:36) on /var/tmp/worker/worker.js:695:26 on process._tickDomainCallback (internal / process / next_tick.js: 135: 7)
The function is very similar to the one shown in the Firestore solution section for aggregation requests:
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
});
});
});
});
And the rating value is an integer 3.
I also ran
npm install firebase-functions @ newest firebase-admin @latest -save
and redeployed, but with no luck.
My package.json contains the following:
{
"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
}
Any help?