Reputation: 6785
I have a query that orders by my timestamp value in my server, the currently timestamp is set by my pojo as a date
data class Timestamp(@ServerTimestamp val timestamp:Date? = null)
This timestamp is place in firestore as
But when I do my fetch code
val snapshot = FirebaseFirestore
.getInstance()
.collection("orders")
.whereEqualTo("uid",currentUser.uid)
.whereLessThan("status",Status.DELIVERED.statusNumber)
.orderBy("status",Query.Direction.DESCENDING)
.orderBy("timestamp",Query.Direction.ASCENDING)
I want to see first on the list the latest orders I did, but instead , is mixing my old orders with the new ones, my goal here is to bring up first the newest orders I placed inside orders collection, but instead it does not order it when new orders are created
Upvotes: 1
Views: 1237
Reputation: 317392
If you want newest documents first, you should do a DESCENDING order on timestamp. If you want the list to be primarily sorted by timestamp, and secondarily sorted by status, the timestamp orderBy it should come before the orderBy on status (right now, you are sorting primarily on status and secondarily on timestamp).
.orderBy("timestamp",Query.Direction.DESCENDING)
.orderBy("status",Query.Direction.DESCENDING)
Upvotes: 2