Dheeraj Rijhwani
Dheeraj Rijhwani

Reputation: 361

List Data in cloud firestore using Timestamp

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);
            }

         }

        }

    });

Upvotes: 0

Views: 975

Answers (1)

Alex Mamo
Alex Mamo

Reputation: 139019

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.

Upvotes: 1

Related Questions