【问题标题】: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.