Reputation: 6805
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.
Upvotes: 3
Views: 14559
Reputation: 28750
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
Upvotes: 11