【问题标题】:The contents of a cloud function get request to firestore keep returning undefined云函数获取对firestore的请求的内容不断返回未定义
【发布时间】:2018-05-19 22:46:54
【问题描述】:

我正在尝试访问 firestore 文档的内容,但我一直未定义。我怀疑我错误地引用了该文档。 变量 updateId 正确打印到控制台,并且是 firebase auth id 的值,它代表 firestore db 中路径的一部分,即 users/fireauth_id。

在文档 users/fireauth_id 中,我有一个名为 token 的字段,我正在尝试返回,但 doc.data.token 始终未定义。我确实尝试使用带有 .doc({updateId}) 而不是 doc(updateId) 的路径,但没有运气。

 exports.updateRequest = functions.firestore
      .document('users/{userId}')
      .onUpdate(event => {

        var newValue = event.data.data();
        var updateId = newValue.update_id;

        return db.collection('users').doc(updateId).get().then(doc => {

              console.log("this doesn't work: %s", doc.data.token)

谢谢。

【问题讨论】:

    标签: node.js google-cloud-functions google-cloud-firestore


    【解决方案1】:

    我认为“doc.data.token”应该是“doc.data().token”

    如果不是这样,那么我认为您要检索的文档不存在。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-01-08
      • 2020-06-29
      • 2018-03-28
      • 1970-01-01
      • 2021-04-11
      • 2021-09-29
      相关资源
      最近更新 更多