首页 > 解决方案 > 如何根据firestore中的特定字段检索集合中的文档?

问题描述

我的数据库结构

- `VHpHJDSvjyYmAteoQEu0AeEHWVg2` [collection]
  - `LI4deUjJK3uqOGhMLDfR` [document]
    - `Gallery` [collection]
      - `RjuCvHvuoz2GRW4Rkuyi` [document]
        - `attachmentId` [field]
        - `type` [field]

获取集合中的所有文档Gallery

Query query = firebaseFirestore.collection(userId).document(docTripId).collection("Gallery");

如何Gallery根据字段type等于“相机”检索集合中的文档?

任何帮助将不胜感激。

标签: androidfirebasegoogle-cloud-firestore

解决方案


那应该是这样的:

CollectionReference  collection = firebaseFirestore.collection(userId).document(docTripId).collection("Gallery");

Query query = collection.whereEqualTo("type", "camera");

然后你要么得到结果,要么收听实时更新


推荐阅读