Limit an ordered list in Firebase

12,952

Data in firebase is ordered lexicographically, so you'll have to get the last of them.

return firebase.database().ref('myUsers').orderByChild("age").limitToLast(3);

Docs with example: https://firebase.google.com/docs/reference/js/firebase.database.Query#limitToLast

Share:
12,952
splunk
Author by

splunk

Updated on June 04, 2022

Comments

  • splunk
    splunk almost 2 years

    I have this:

    name  |  age
    ______|_____
    Anne  |  28
    Carl  |  20 
    Sarah |  13
    Lucy  |  56
    John  |  22 
    Mark  |  44
    

    How do I retrieve the name of the 3 youngest people with Firebase?

    I tried with:

    return firebase.database().ref('myUsers').orderByChild("age").startAt().limit(3);

    but I get an error:

    Supplied parameters do not match any signature of call target.