如何从 firestore 的路径中获取 bool 值
How to get a bool value from a path from firestore
我想从 Firestore 获取一个 bool 值,但这样做时我总是得到 undefined。
我尝试使用以下代码获取值:
const flag = admin.firestore().collection("flags").doc("Air").sent;
当我尝试打印 flag
的值时,我得到 undefined
这是值的路径:
你能帮我发现我的错误吗?
您需要在 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.
我想从 Firestore 获取一个 bool 值,但这样做时我总是得到 undefined。
我尝试使用以下代码获取值:
const flag = admin.firestore().collection("flags").doc("Air").sent;
当我尝试打印 flag
的值时,我得到undefined
这是值的路径:
你能帮我发现我的错误吗?
您需要在 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.