[英]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? 如何使用Firebase检索3个最年轻的人的姓名?
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.
Data in firebase is ordered lexicographically, so you'll have to get the last of them. firebase中的数据按字典顺序排序,因此您必须获取最后一个。
return firebase.database().ref('myUsers').orderByChild("age").limitToLast(3);
Docs with example: https://firebase.google.com/docs/reference/js/firebase.database.Query#limitToLast 文档示例: https : //firebase.google.com/docs/reference/js/firebase.database.Query#limitToLast
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.