1

I am using the below query to get documents before given documents snapshot. when I use descending: false I get initial 5 documents but I want immediate 5 documents before the given documents. When I use descending: true I get an empty list. Please help me. What I am doing wrong here.

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();
      }
Mofidul Islam
  • 378
  • 3
  • 12

1 Answers1

1

EDIT: Also make sure you have initialized an index on the field you are trying to order by, take a look here!

return Firestore.instance
            .collection(FIREBASE_COLLECTION_MESSAGES)
            .document(currentUserID)
            .collection(clientID)
            .orderBy('TIMESTAMP_FIELD', descending: true)
            .endBeforeDocument(documentSnapshot)
            .limit(5)
            .snapshots();
MKougiouris
  • 2,821
  • 1
  • 16
  • 19