如何在云功能中获取快照的ID?

时间:2019-10-16 19:06:35

标签: google-cloud-platform google-cloud-firestore

当将新文档添加到Firestore时,我正在使用云功能进行触发,但是我无法在网上找到如何获取此文档的ID。

这是我的代码:

    exports.sendWelcomeEmail = functions.firestore
  .document(`users/{user}`)
  .onCreate(async (snap, context) => {

      const email = snap.data().userEmail; // The email of the user.
      const displayName = snap.data().userName; // The display name of the user.

  return sendWelcomeEmail(email, displayName);
  });

我需要从“快照”中获取ID,该怎么办?

1 个答案:

答案 0 :(得分:0)

您可以像使用任何JS属性一样访问特定字段,这是指向documentation的链接。

相关问题