【发布时间】:2019-03-21 19:55:28
【问题描述】:
我正在尝试使用 Cloud Firestore 触发器来自动更新 Algolia“用户”索引中的记录。
这是我们的云功能:
exports.updateUser = functions.firestore
.document('users/{id}').onUpdate((change, context) => {
const afterData = change.after.data()
return algoliaIndex.partialUpdateObjects([{afterData}]).catch((err) => {
return console.error(new Error(err))
})
})
在我们的 firebase 函数日志中,我们看到了这个错误:
Error: Usage: index.partialUpdateObjects(arrayOfObjects[, callback])
at Index.partialUpdateObjects (/user_code/node_modules/algoliasearch/src/Index.js:136:11)
at exports.updateUser.functions.firestore.document.onUpdate (/user_code/index.js:19:26)
at cloudFunctionNewSignature (/user_code/node_modules/firebase-functions/lib/cloud-functions.js:114:23)
at cloudFunction (/user_code/node_modules/firebase-functions/lib/cloud-functions.js:144:20)
at /var/tmp/worker/worker.js:827:24
at process._tickDomainCallback (internal/process/next_tick.js:135:7)
我们做错了什么?
谢谢!
编辑: 我已经更新了下面的代码,除了 Algolia 需要在对象中传递对象 ID 以便它更新正确的记录之外,它现在可以工作了。如何在“afterData”对象中引用 ObjectID?
【问题讨论】:
标签: firebase vue.js google-cloud-firestore google-cloud-functions algolia