-1

My database:

enter image description here

Based on this, how can I get a recipe, searching by a ingredient description using rest service in firebase? I've tried it: /recipe.json?orderBy="ingredients/description"&equalTo="teste"

but I had no success.

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807

1 Answers1

0

Firebase Database queries can search on values at a known path under the children of the location you query. Your values are instead at a dynamic path: the teste ingredient can be ingredient/0, ingredient/1, etc. That is a query that is not possible with the Firebase database.

With your current data a simple change to allow the query is to use the ingredient description as the key:

"ingredients": {
  "teste": 1,
  "teste2": 3
}

Then you can query with something like:

/recipe.json?orderBy="ingredients/teste"&startAt=0

In general this type of nesting of collections is discouraged with the Firebase Realtime Database. For more information, see:

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
  • Well, the structure I need is: A recipe {description, level...} which has 1 or more ingredients {description, amount}. How do you recommend to structure this nesting using firebase database? – Rafael Reis Oct 06 '17 at 14:55