How to return only 10 records in firebase?

Asked

Viewed 96 times

1

I wish to return only an exact number of firebase records, but I don’t know how it should be done, is there any way?

  • 1

    Hello You can post your code that you have developed so far. Check this link if you are interested https://answall.com/tour

1 answer

0


To return only an X number of records, use the functions limitToFirst or limitToLast.

limitToFirst will return the first X records and limitToLast the latest X records, based on the ordered data applied.

For example, the query below will return the last 2 records, considering the orderm by column Weight.

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

Now to do that

I want to dynamically pick up every 2 records

that you wrote in the comments, can use the functions startAt and endAt. Whereas your records will be ordered according to a certain value, a startAt equal to X and endAt equal to Y will return the records from the sorting value X to the value Y.

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

See the documentation links that can help: COMPLEX FILTERING

  • While this link may answer the question, it is best to include the essential parts of the answer here and provide the link for reference. Replies per link only can be invalidated if the page with the link is changed.

  • Okay, I’ll update the answer.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.