Firebase 函数:'onCreate' 函数未被调用

Firebase Functions: 'onCreate' function isn't being called

我正在为 Android 开发一个日记应用程序,它使用 Firebase 的实时数据库来存储 memory 对象。一个 memory 对象包含 title, image, text, list of tags, and more...

当用户将新记忆发布到数据库时,我想通过将记忆索引到 Algolia 来使其可搜索。为此,我将此函数部署到我的 Firebase Functions 项目中:

exports.indexentry = functions.database.ref('/Diary/{userId}/{memoryId}').onCreate(
async (data, context) => {
  const index = client.initIndex(ALGOLIA_MEMORIES_INDEX_NAME);
  const firebaseObject = {
    text: data.val(),
    objectID: context.params.memoryId
  };

  await index.saveObject(firebaseObject);
  return data.after.ref.parent.child('last_index_timestamp').set(Date.parse(context.timestamp));
});

但是上传新内存时并没有调用这个函数。有人可以帮助我识别问题吗?

编辑:检查 Cloud Function 日志后,我发现调用了该函数,但发生了 TypeError: Cannot read property 'ref' of undefined 错误。

我通过更改函数代码解决了 TypeError: Cannot read property 'ref' of undefined 错误:

return data.after.ref.parent.child('last_index_timestamp').set(Date.parse(context.timestamp));

至:

return data.ref.parent.child('last_index_timestamp').set(Date.parse(context.timestamp));

我认为此错误的原因是 onCreate() 函数的 data 更改对象没有 after 变量。