0

I am trying to list the data in Firestore by Timestamp but it can't happening. With the whereGreaterThan and OrderBy.

    db.collection("Users_Photos").document(uid).collection("ImageData").whereGreaterThan("image_timestamp",1506816000).orderBy("image_timestamp").addSnapshotListener(new EventListener<QuerySnapshot>() {
        @Override
        public void onEvent(QuerySnapshot documentSnapshots, FirebaseFirestoreException e) {

            if(e!=null)
            {

            }
         for (DocumentChange doc : documentSnapshots.getDocumentChanges())
         {
            if (doc.getType()==DocumentChange.Type.ADDED)
            {
                Photo photo = doc.getDocument().toObject(Photo.class);
                photosList.add(photo);
                photoListAdapter.notifyDataSetChanged();

 String name = doc.getDocument().getString("image_location");
              Log.d(TAG,name);
            }

         }

        }

    });
Dheeraj Rijhwani
  • 351
  • 5
  • 18

1 Answers1

1

You are not getting your data sorted by timestamp, becasue you are not using the correct way of setting the data. As I see you are using the current time in millis instead of using server value timestamp. Here is how you can set the timestamp correctly in Cloud Firestore. So do as explained in that post, and your data will be sorted correctly.

Alex Mamo
  • 130,605
  • 17
  • 163
  • 193