splunk splunk - 1 month ago 17
Javascript Question

Limit an ordered list in Firebase

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.

Answer

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