首页 > 解决方案 > 我有一个 Firestore 数据库,在我的 Flutter 应用程序中我检索到了我需要的 docID。如何检索文档 usign docID 的特定字段?

问题描述

我找到了我需要的文档的文档 ID。我在数据库“maindb”中的每个文档都有 4 个字段(看守、老人、脉冲、临时)。如果我的用户 ID 可用,那么仅检索脉冲字段中的整数值的语法是什么?

标签: firebasefluttergoogle-cloud-firestore

解决方案


我直接从 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 相关的整个文档。然后,您可以从中获取所需的任何条目。


推荐阅读