【问题标题】:Firestore end before documents not working properlyFirestore 在文档无法正常工作之前结束
【发布时间】:2020-10-16 20:10:38
【问题描述】:

我正在使用以下查询在给定文档快照之前获取文档。当我使用降序时:false 我得到最初的 5 个文件,但我想要在给定文件之前立即获得 5 个文件。当我使用 descending: true 时,我得到一个空列表。请帮我。我在这里做错了什么。

Stream<QuerySnapshot> getConversationBefore(String currentUserID,String clientID,DocumentSnapshot documentSnapshot)
      {
           return Firestore.instance
            .collection(FIREBASE_COLLECTION_MESSAGES)
            .document(currentUserID)
            .collection(clientID)
            .orderBy(TIMESTAMP_FIELD, descending: false)
            .endBeforeDocument(documentSnapshot)
            .limit(5)
            .snapshots();
      }

【问题讨论】:

    标签: firebase flutter google-cloud-firestore


    【解决方案1】:

    编辑: 还要确保您已在尝试排序的字段上初始化索引,看看here

    return Firestore.instance
                .collection(FIREBASE_COLLECTION_MESSAGES)
                .document(currentUserID)
                .collection(clientID)
                .orderBy('TIMESTAMP_FIELD', descending: true)
                .endBeforeDocument(documentSnapshot)
                .limit(5)
                .snapshots();
    

    【讨论】:

    • 我进行了编辑,我不确定您的意思是“不接受 desc 参数”,除非我误解了您的堆栈,并且它不是 firebase ...否则 sn-p 来自示例!
    • 我正在使用 firestore 颤振插件,其中 order by 接受一个字段和可选的布尔值而不是字符串
    • 看看这里,如果它有助于告诉我改变我的答案stackoverflow.com/questions/51434167/…
    • 我会试试这个
    猜你喜欢
    • 2019-03-13
    • 2020-07-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-11-01
    • 2021-07-19
    • 1970-01-01
    相关资源
    最近更新 更多