Firebase Filtering Data - Firebase

What are the different ways of filtering Firebase data?

There are many ways by which data is filtered in Firebase.

Limit to First and Last

  • limitToFirst method enables in returning the specific number of items starting from the first one.
  • limitToLast method enables in returning the specific number of items starting from the last one.

In the illustration, database has only two players so the query is limited to only one player.

The first player is logged from first query and the last player is logged from the second query by the console.

Firebase Filtering Data Limit to First Last

What are the other Firebase filtering methods?

startAt(), endAt() and equalTo() are some of the filtering methods offered by Firebase. They can also be used by combining with the ordering methods.

For instance, filters are combined with orderByChild() method as:

First query orders the elements by name and filter with the name ‘Amanda’ from the player list. Both the players are logged in console.

Second query logs ‘Amanda’ as the query is ended by name.

Third query logs ‘John’ as the query search for player with the name.

Fourth illustration display how filters are combined with the value ‘age’. Since number value represents age, number is passed inside startAt() instead of string.

Firebase Filtering Data Start End Equal

All rights reserved © 2020 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

Firebase Topics