Google cloud firestore 在'之后获取文档字段;onCreate';谷歌云功能(firestore)

Google cloud firestore 在'之后获取文档字段;onCreate';谷歌云功能(firestore),google-cloud-firestore,google-cloud-functions,Google Cloud Firestore,Google Cloud Functions,我已经编写了一个谷歌云函数,每当一个新的用户文档被添加到我的firestore数据库时,该函数就会启动 棘手的(我希望的)部分已经完成,但现在我正在努力访问创建的文档中的实际字段。这是一个带有“email”字段的简单用户文档 这是我的功能。我需要用什么替换电子邮件 exports.sendWelcomeEmail = functions.firestore .document('users/{userId}') .onCreate((snapshot, context) => {

我已经编写了一个谷歌云函数,每当一个新的用户文档被添加到我的firestore数据库时,该函数就会启动

棘手的(我希望的)部分已经完成,但现在我正在努力访问创建的文档中的实际字段。这是一个带有“email”字段的简单用户文档

这是我的功能。我需要用什么替换电子邮件

exports.sendWelcomeEmail = functions.firestore
  .document('users/{userId}')
  .onCreate((snapshot, context) => {
        sendEmail(snapshot.email)
});

您可以在中找到您的用户数据 snapshot.data()

exports.sendWelcomeEmail = functions.firestore
  .document('users/{userId}')
  .onCreate((snapshot, context) => {
        let user = snapshot.data();
        sendEmail(user.email)
});