I have a table view that displays users ordered by their created date in descending order (newest member is sorted first). In that same table view, I also want to find and show all male users in new york between the ages of 30 and 40 that is based on user settings.
My database looks as follows
{
"Ka8xxTgyFB8yYKH50j" : {
"created" : 1583258308.2321649,
"data" : "male_newyork_30"
},
"K222xTgyFBF33FD50j" : {
"created" : 1583358308.2321649,
"data" : "male_newyork_35"
},
"Ka32T23R328yYKH50j" : {
"created" : 1584258308.2321649,
"data" : "male_seattle_30"
},
"F323F32FB8yYKH50j" : {
"created" : 1583558308.2321649,
"data" : "female_newyork_30"
}
...
}
As referenced in Advanced Firebase Query with filter in Swift, I tried the following with a limit to last 6 users (so it doesn't download everything):
usersRef.queryOrderedByChild("data").queryStartingAtValue("male_newyork_30")
.queryEndingAtValue("male_newyork_40").queryLimited(toLast: 6).observeSingleEventOfType(
.Value, withBlock: { snapshot in
print(snapshot)
})
However, I cannot paginate with this data because I don't know what to keep track of to load the next 6 users.
Normally when I add pagination, I'd query by user created date and keep track of the last user's created date to compare it to the next batch of data. But this approach only paginates and doesn't filter data.
How can I paginate and filter my data? Any help is very appreciated!