【问题标题】:How to get a bool value from a path from firestore如何从firestore的路径中获取布尔值
【发布时间】:2022-01-07 13:23:03
【问题描述】:

我想从 Firestore 获取一个布尔值,但这样做时总是不确定。

我尝试使用以下代码获取值:

const flag = admin.firestore().collection("flags").doc("Air").sent;

当我尝试打印标志的值时得到undefined

这是值的路径:

你能帮我找出我的错误吗?

【问题讨论】:

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


    【解决方案1】:

    您需要在doc() 方法上调用get()

    const doc = await admin.firestore().collection("flags").doc("Air").get();
    const flag = doc.data().sent; // doc.get('sent') should also work.
    console.log(flag); // should print false
    // I added "await" and "get()" method. Your function should be an "async"
    // function.
    

    【讨论】:

      猜你喜欢
      • 2021-06-14
      • 2015-11-12
      • 1970-01-01
      • 2014-02-12
      • 2019-12-30
      • 1970-01-01
      • 2016-07-15
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多