question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Descending query when using orderByChild()

See original GitHub issue

Hey there, @pautena and I are developing an Android app with a Firebase backend at Hack The North 2016.

We’ve faced this problem and we think that could be nice to solve with a new feature in future versions:

  • When using the Firebase Realtime Database we were trying to get a DatabaseReference like this mFirebaseDatabaseReference.child(User.USER_CHILD).orderByChild("points") to make a ranking, but we faced the problem that Firebase only retrieves the ordered data in ascendent mode.

We think that would be awesome to have the possibility to query orderByChild with some kind of parameter which indicates if you want your data ordered in an ascendent or descendent way.

We post this issue to stay tuned for improvements in this area and hope Firebase become even more cool! 😄

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:11 (2 by maintainers)

github_iconTop GitHub Comments

46reactions
anrodoncommented, Sep 18, 2016

We’ve found a good solution if you’re using the DatabaseReference to populate a FirebaseRecyclerAdapter, here it goes:

  • Inside the FirebaseRecyclerAdapter declaration, override the getItem() function just like we did:
@Override
public User getItem(int position) {
        return super.getItem(getItemCount() - 1 - position);
}

Hope it helps anybody with the same problem 😄

0reactions
Niraj-Ranjancommented, Jun 13, 2021

Hi Suhailakl, could you better explain where this code should be included? I can not make it work. Thank you.

You can add it to onCreate

Read more comments on GitHub >

github_iconTop Results From Across the Web

Sorting in descending order in Firebase database [duplicate]
If your data query is too large to sort client side you can do firebase.database().ref('books').orderByChild('ups').limitToLast(2).
Read more >
how to implement descending orderByChild() - Google Groups
The trick to get descending order is to invert the number of likes, so: item. order = -1 * item.
Read more >
Order and limit data with Cloud Firestore | Firebase - Google
By default, a query retrieves all documents that satisfy the query in ascending order by document ID. You can specify the sort order...
Read more >
How to make a descending order in Firebase - YouTube
this.celebsDatabase = af.list('/Celebrity', { query : { orderByChild : "order", }});sendMultihypes(multihypes: number){ var holderhypes ...
Read more >
Ordering and limiting Firestore queries in descending order
Explore further. For detailed documentation that includes this code sample, see the following: Order and limit data with Cloud Firestore · Ordering and ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found