javascript - 文档参考.get() 不工作
问题描述
我只是想找到这个布尔值,如果它是真的,那么它将执行一个代码。否则,它将执行另一个代码。我似乎无法在 Firebase 中读取此布尔值。
它在这里说我可以做,.get(fieldPath)
但我可能做错了。Firebase 文档真的很糟糕。哈哈
checkIfLoggedIn = () => {
firebase.auth().onAuthStateChanged(user => {
if (user) {
const uid = firebase.auth().currentUser.uid;
const db = firebase.firestore();
db.collection('users')
.doc(uid)
.get('uid.isStore')
.then(snapshot => {
// Trying to find how to do this
console.log(snapshot);
});
this.props.navigation.navigate('mainNav');
} else {
this.props.navigation.navigate('signup');
}
});
};
解决方案
我认为您想要的是类似于以下的逻辑:
db.collection('users')
.doc(uid)
.get()
.then(documentSnapshot => {
let isStore = documentSnapshot.get('isStore');
// Value of isStore here ...
});
链条是:
db.collection
->CollectionReference
CollectionReference.doc()
->DocumentReference
DocumentReference.get()
->Promise<DocumentSnapshot>
DocumentSnapshot.get()
-> 字段值
也可以看看:
推荐阅读
- angular - 如何计算与角度条件匹配的项目?
- java - 如何使用 java + selenium 设置 chrome 浏览器语言?
- python - 试图通过绘制图形来可视化时间复杂度,意外输出
- qt - 带有精灵或 SpriteSequence 的 QML Tumbler
- android - 我怎样才能有一个日历,其中日期为水平行,时间为垂直列
- azure-cosmosdb - 确定 cosmosdb 查询从哪个位置运行
- android - 无法更改 Kotlin 中的语言区域设置
- ios - 表视图中的重复行
- c++ - 如果 Struct 包含互斥体,则 C++ 将初始化器列表推送到标准向量上的问题
- rss - 如何为 Bot Builder 阅读 RSS