【发布时间】:2018-10-23 14:19:34
【问题描述】:
Cloud Firestore:TypeError:无法读取未定义的属性“ref”
我正在使用 Cloud Functions 更新 Cloud Firestore 父集合中的 cmets 编号,因此当添加评论时,Cloud Functions 可以自动更新评论编号。
exports.updateCommentNumbers = functions.firestore
.document('postlist/{postlistId}/comments/{commentsID}')
.onCreate(event =>
{
const collectionRef = event.after.ref.parent;
const countRef = collectionRef.parent.child('comment_number');
//const previousValue = event.data.previous.data();
let increment;
if (event.after.exists() )
{
increment = 1;
}
else
{
return null;
}
return countRef.transaction((current) =>
{
return (current || 0) + increment;
}).then(() =>
{
return console.log('Comments numbers updated.');
});
});
我遇到了我不明白的错误。你能告诉我有什么问题吗?
TypeError:无法读取未定义的属性“ref” 在exports.updateCommentNumbers.functions.firestore.document.onCreate.event (/user_code/index.js:46:35) 在对象。 (/user_code/node_modules/firebase-functions/lib/cloud-functions.js:112: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:82:36) 在 /var/tmp/worker/worker.js:716:24 在 process._tickDomainCallback (internal/process/next_tick.js:135:7)
【问题讨论】:
标签: javascript firebase google-cloud-firestore google-cloud-functions