I'm trying to get the top 4 scores using a scoring system with the new Firebase queries in Swift. My database looks like this:
gameScores
$gameType
$userId: 3
$userId: 2
$userId: 4
$userId: 1
$userId: 5
$userId: 8
$userId: 2
$gameType
$userId: 1
The integer is the score for that userId. I want to get the 4 highest scores for a given gametype. Ties don't really matter, the important part is ordering them then pulling these first 4. The integer is the score for that userId. I tried using a query which looks like this:
DataService.ds.REF_GAMESCORES.child(self.gameType).queryOrderedByValue().
queryLimitedToFirst(4).observeEventType(.Value, withBlock: {(snapshot) in
but when I print the snapshot it puts them in the same order they are in the database. I have been working with the observers for a while but this is my first time working with Firebase queries.