0

I want to retrieve data from Firebase. The retrieving data should be visible and have appropriate property "vis" and flag "true". It's a quite simple task. But I also want specific order, so in the beginning should go child with property "pos" equal 1, than 2, and etc.

There is my current line of code

mQuery = mDatabaseReference.orderByChild("vis").equalTo("true");

The data structure looks like:

common
 code:"common"
 name:"Common"
 pos:"5"
 vis:"false"

 court
 code: "court"
 name: "Court reform"
 pos: "2"
 vis: "false"

 june12
 code: "june12"
 name: "12 June"
 pos: "1"
 vis: "true"
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Ya Si
  • 819
  • 7
  • 12
  • You can combine the two values that you want to use into a single property, i.e. `vis_pos: "true_1"`. Then you can order/filter on that property and get the results you want. See my answer here: http://stackoverflow.com/questions/26700924/query-based-on-multiple-where-clauses-in-firebase – Frank van Puffelen May 21 '17 at 03:08
  • Thank you Frank! I have already seen that question before. I had different task. I want to retrieve data that have value "true" for properties "vis" and at the same type this retrieving data should be displayed in ascending order. That's why I use another property "pos". I found simple solution: I deleted property "vis" and changed the line of code in my app. mQuery = mDatabaseReference.orderByChild("pos").startAt("100"); So after that, I retrieve only data that start at "100". – Ya Si May 21 '17 at 15:49

1 Answers1

0

The short answer is no. From the docs:

You can only use one order-by method at a time. Calling an order-by method multiple times in the same query throws an error. https://firebase.google.com/docs/database/cpp/retrieve-data#sorting_and_filtering_data

You can limit the Range of data using a filter function: https://firebase.google.com/docs/database/cpp/retrieve-data#filtering_data

Be sure to watch the Firebase for SQL devs series. Specifically, the video on denormalization (#6) and the follow up Multi-path updates (#7). Multipath updates can be performed server side using Cloud function triggers.

James Poag
  • 2,320
  • 1
  • 13
  • 20