Reputation: 327
I've created an app and I am using firebase as well but I want to order the documents by timestamp such that my documents will be ordered from recently added ones to older ones.
I wonder if there is a solution rather than using orderBy method because my project is very big.
please help me.
Note: I am devolping the app using flutter & dart.
Upvotes: 2
Views: 2431
Reputation: 598797
Firebase Realtime Database always returns results in ascending order. There is no way to order descending order.
This means you have two common options:
If you want to retrieve a subset of the items, keep in mind that you can combine any of these approaches with limitToFirst()
and limitToLast
. For example, to get the 10 most recent messages, you could:
Also see:
limitToLast
approach mentioned above.orderByChild()
.Upvotes: 3