1

I use Ionic and Firebase in my project.

I need to filter users by gender and, due to there is too much data, I also have to implement pagination for ease of navigating through. I have been dealing with this problem for a long time, but still could not find a valid solution.

My database structure is:

here

My code is:

ref = this.afDB.database.ref('Users').orderByChild('Gender').equalTo('male').orderByChild('Id').startAt(lastItemKey).limitToFirst(10)
Sujal Patel
  • 2,444
  • 1
  • 19
  • 38

1 Answers1

2

You can't call orderBy...() multiple times on the same query. See Query based on multiple where clauses in Firebase

But you can use the two-parameter version of equalTo() to accomplish what you want:

db.ref('Users').orderByChild('Gender').equalTo('male', lastItemKey).limitToFirst(10)

The lastItemKey in this snippet is used when there are multiple child nodes with Gender equal to male to determine at which one to start.

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807