【发布时间】:2018-09-07 18:18:46
【问题描述】:
我为谷歌云功能编写了这个节点 js 函数,以将 Firebase 数据库节点条目索引到 Algolia。
exports.indexlisting_algolia =
functions.database.ref('/Listings/{listingId}')
.onWrite((change, context) => {
const index = algolia.initIndex('Listings');
const before = change.before; // snapshot before the update
const after = change.after; // snapshot after the update
const before_data = before.val();
const after_data = after.val();
after_data.objectID = context.params.listingId;
console.log(Date.now());
console.log(context)
return index.saveObject(after_data)
.then(
() => change.after.ref.child('last_index_timestamp').set(
Date.parse(context.timestamp)));
})
该函数有效,但它不会停止执行,它只是一遍又一遍地重复自己。出了什么问题,我该如何解决?
【问题讨论】:
标签: node.js firebase firebase-realtime-database google-cloud-functions