【发布时间】:2019-02-12 06:16:27
【问题描述】:
我有这个节点 js 函数,一旦对节点列表进行添加/更新/删除,它就会尝试更新 Algolia 索引
exports.indexlisting_algolia =
functions.database.ref('/Listings/{listingId}').onWrite((snapshot, context) => {
const index = algolia.initIndex('Listings');
// var firebaseObject = snapshot.data;
var firebaseObject = snapshot.data.val();
console.log("test ",firebaseObject)
firebaseObject.objectID = context.params.listingId;
return index.saveObject(firebaseObject).then(
() =>
snapshot.data.adminRef.parent.child('last_index_timestamp').set(
Date.parse(event.timestamp)));
});
这是我的错误 thraceback
TypeError:无法读取未定义的属性“val” 在exports.indexlisting_algolia.functions.database.ref.onWrite (/user_code/index.js:807:40) 在对象。 (/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:733:24 在 process._tickDomainCallback (internal/process/next_tick.js:135:7)
第 807 行是这个函数
var firebaseObject = snapshot.data.val();
我做错了什么,我该如何解决?
【问题讨论】:
标签: node.js firebase google-cloud-functions