0

Is it possible to order by 2 different params in firebase REST API and what's the correct api call should for that:

I need to get posts by userId and category. What's the correct endpoint should be for that?

 FIREBASE_URL/?orderBy="userId"&orderBy="category"&equalTo="${userId}"&equalTo=${category}`;

{
  /* Visit https://firebase.google.com/docs/database/security to learn more about security rules. */
  "rules": {
    ".read": "true",
    ".write": "auth != null",
    "todos": {
      ".indexOn": ["category", "userId"]
    }
  }
}
Doug Stevenson
  • 297,357
  • 32
  • 422
  • 441
lecham
  • 2,294
  • 6
  • 22
  • 41
  • You can't sort by multiple fields with Realtime Database. – Doug Stevenson May 29 '19 at 12:38
  • So what can be a solution in this case? 2 API calls, one for sort by id, second one by category? – lecham May 29 '19 at 12:49
  • Click through to the marked duplicates for some alternatives. – Doug Stevenson May 29 '19 at 13:09
  • @DougStevenson It doesn't my question at all – lecham May 29 '19 at 13:21
  • @drevival Firebase Database queries can only order/filter on a single property. In many cases it is possible to combine the values you want to filter on into a single (synthetic) property. For an example of this and other approaches, see my answer in the question Doug linked: http://stackoverflow.com/questions/26700924/query-based-on-multiple-where-clauses-in-firebase – Frank van Puffelen May 29 '19 at 14:44

0 Answers0