firebase - 我有一个 Firestore 数据库,在我的 Flutter 应用程序中我检索到了我需要的 docID。如何检索文档 usign docID 的特定字段?
问题描述
我找到了我需要的文档的文档 ID。我在数据库“maindb”中的每个文档都有 4 个字段(看守、老人、脉冲、临时)。如果我的用户 ID 可用,那么仅检索脉冲字段中的整数值的语法是什么?
解决方案
我直接从 Flutter Fire文档中得到了这个。我不确定您是否使用它来连接到 Firestore,但至少它应该是一个很好的起点。
FirebaseFirestore.instance
.collection('users')
.doc(userId) <--- Just use the document ID here
.get()
.then((DocumentSnapshot documentSnapshot) {
if (documentSnapshot.exists) {
print('Document exists on the database');
}
});
这将返回与该 userId 相关的整个文档。然后,您可以从中获取所需的任何条目。
推荐阅读
- elasticsearch - Grafana:如何根据 ErrorLevel 以不同颜色显示错误日志?
- python - 使用决策树时,预期 2D 数组,得到 1D 数组
- machine-learning - 使用 Keras 提高神经网络的准确性
- google-app-engine - GCP Cloud http负载均衡器上的websocket_handshake_failed,响应为403
- ios - 正则表达式不允许在字符串 swift ios 中盯着空格
- youtube - YouTube 超级留言层的 UI 颜色是什么?
- python - import graphviz 在 jupyter notebook 中有效,但相同的代码在 Pycharm 中无效
- javascript - 标题 href 在 iframe 中打开,但 img href 不是 JS
- android - 使用 viewmodel LiveData 处理 recyclerview 中的滑动删除以进行数据存储
- elasticsearch - Kibana 服务器还没有准备好!尝试可视化数据推送到 Elasticsearch