How to return only 10 records in firebase?

1

I want to return only an exact number of firebase records, but I do not know how it should be done, is there a way?

    
asked by anonymous 30.05.2018 / 20:48

1 answer

0

To return only an X amount of records, use the limitToFirst or limitToLast functions. limitToFirst will return the first X records and limitToLast the last X records, based on the data ordering applied.

For example, the query below will return the last 2 records, considering the order by the weight column.

curl 'https://dinosaur-facts.firebaseio.com/dinosaurs.json?orderBy="weight"&limitToLast=2&print=pretty'

Now to do this

  

I want to get every 2 records dynamically

you wrote in the comments, you can use the startAt and endAt functions. Since your records will be sorted by a given value, a startAt equal to X and endAt equal to Y will return the records from the sort value X to the value Y.

Then in this case you will need to sort your data based on a numeric sequence (1, 2, 3, ...) and do = startAt = 1 & endAt = 2 , startAt = 3 & endAt = 5 , and so on.

See the documentation links that might help: COMPLEX FILTERING

    
30.05.2018 / 21:05