I'm using firebase for a large-ish database, with each entry using an autoid key. To get, say, the last ten entries, I can use:
ref.queryLimitedToLast(10).observeSingleEventOfType(.Value, withBlock: { snapshot in
for item in snapshot.children {
//do some code to each item
}
})
However, I can't for the life of me work out how to then get just the ten entries before that. Eg. if the database had 100 entries, my code would return 90-100, but how would I then get entries 80-90 (without, for example, querying the last 20 and throwing half away, as it seems inefficient)?
Edit: I ended up using
ref.queryOrderedByChild("timecode").queryEndingAtValue(final).queryLimitedToLast(10).observeSingleEventOfType(.Value, withBlock: { snapshot in
for item in snapshot.children {
//do some code to each item, including saving a new value of 'final'
}
})
and saving the value 'final' as the timecode of the last update. that is, first i would get results, 90-100, say, and save the timecode of 90 as final (minus one second), then use this for the ending value, etc... to find results 80-89. Just as Jay describes below, but using a timestamp instead of an index number (as it was already in there)
Edit 2: Also, to get it working better, I also added ".indexOn": "timecode" to the firebase rules for the database
finalin your code? Is it a number or a timestamp? - IvanPavliuk