【问题标题】:How do I access data from a top-level document in a Cloud firestore trigger with Cloud functions?如何使用 Cloud 函数从 Cloud Firestore 触发器中的顶级文档访问数据?
【发布时间】:2019-07-02 06:56:28
【问题描述】:

示例:如果我的触发器在 (Users/{userId}/Billings/{billingId}) 等路径上是 onWrite,我如何访问用户文档数据

functions.firestore.document('Users/{userId}/Billings/{billingId}')
     .onWrite((change, context) => {

    });

我知道我可以通过 context.params 和通配符 userId 和 billingId 访问帐单数据。

我将如何访问触发此事件的用户文档数据?

【问题讨论】:

    标签: javascript firebase google-cloud-firestore google-cloud-functions


    【解决方案1】:

    不能直接从参数中获取用户文档。但是你可以通过参数确定路径,然后用 Admin SDK 加载文档。

    admin.firestore().doc(`users/${context.params.userId}`).get()...
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-02-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-03-27
      • 2018-06-22
      相关资源
      最近更新 更多