【问题标题】:How to retrieve documents in collection based on particular field in firestore?如何根据firestore中的特定字段检索集合中的文档?
【发布时间】:2018-08-05 13:59:43
【问题描述】:

我的数据库结构

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

获取集合中的所有文档Gallery

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

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

我们将不胜感激。

【问题讨论】:

    标签: android firebase google-cloud-firestore


    【解决方案1】:

    应该是这样的:

    CollectionReference  collection = firebaseFirestore.collection(userId).document(docTripId).collection("Gallery");
    
    Query query = collection.whereEqualTo("type", "camera");
    

    然后你要么get the results,要么listen for realtime updates

    【讨论】:

    • 在这种情况下,您正在获取整个文档对吗?
    • 上面的代码实际上并没有检索到任何东西,但是如果在上面调用getDocuments(),它确实会得到整个文档。这是 Firestore 客户端处理的唯一级别:您无法获取文档的子集。
    猜你喜欢
    • 2019-09-23
    • 2021-02-25
    • 1970-01-01
    • 2020-10-02
    • 1970-01-01
    • 2021-11-04
    • 2020-06-08
    • 2022-09-27
    相关资源
    最近更新 更多