0

I have a sharded dataset like the example below where every month a new shard is created with vote counts recorded on posts. (This isn't exactly the data I'm using but representative of the structure I need)

{
  "votes" : {
    "201604" : {
      "First Post" : {
        "count" : 1,
        "label" : "First Post"
      },
      "Second Post" : {
        "count" : 3,
        "label" : "Second Post"
      },
      "Third Post" : {
        "count" : 1,
        "label" : "Third Post"
      }
    }
    "201605" : {
      "First Post" : {
        "count" : 5,
        "label" : "First Post"
      },
      "Second Post" : {
        "count" : 3,
        "label" : "Second Post"
      },
      "Third Post" : {
        "count" : 2,
        "label" : "Third Post"
      }      
    }
  }
}

What I need to do is return the top X Posts by Count for the last Y shards (descending)

This query doesn't work as I can't combine multiple orderBy clauses but in my mind is explaining what I'm trying to achieve;

database.child("votes").limitToLast(2).orderByValue().orderByChild("count").limitToFirst(10);
CodeChimp
  • 4,745
  • 6
  • 45
  • 61
  • 1
    The first answer on this question http://stackoverflow.com/questions/26700924/query-based-on-multiple-where-clauses-in-firebase does a pretty good job of explaining the ways you can do this in firebase. Multiple orderBy clauses don't work in firebase. There are several work-arounds, but I agree, it would be nice if there was a nice simple way to do this. – Luke Schlangen May 26 '16 at 14:58
  • Thanks for the pointer, the work arounds aren't great as I don't want to be pulling a lot of data to the device to process and the others don't seem to be useful for a mobile only implementation. I'll have to go back and think of alternatives. – CodeChimp May 27 '16 at 06:51
  • Maybe my answers helps you https://stackoverflow.com/questions/46156902/make-firebaserecycleradapter-get-data-under-conditions-and-not-all-of-them/46384299#46384299 – gtzinos Sep 24 '17 at 19:53

0 Answers0