1

I have this structure:

enter image description here

I found this: https://github.com/angular/angularfire2/blob/master/docs/4-querying-lists.md and also I read firebase docs.

I try this:

return this.db.list(`${this.API_EVENTS_PATH}`, {
  query: {
    equalTo: {
      value: 'sharikov.vladislav@gmail.com',
      key: 'from'
    }
  }
});

This gives nothing: empty array. Why?

And another question is: how to I can filter items by 2 fields? I need from=sharikov.vladislav@gmail.com&status=ACCEPTED for example.

How it is possible to do it with FB?

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
Sharikov Vladislav
  • 7,049
  • 9
  • 50
  • 87

1 Answers1

2

For your first question.

Before you use the EqualTo filter there should first be an OrderBy filter... This OrderBy filter tells the query which field should EqualTo refer to... So your query should look like this.

let path = this.API_EVENTS_PATH;
return db.list(path , {
  query: {
    orderByChild: 'from',
    equalTo: 'sharikov.vladislav@gmail.com',
  }
});

For your second question

How to filter items by 2 fields

In Nosql database like firebase you are normally allowed to filter by only 1 field. Every other manipulations are done considering on how you organise your database. Check out this firebase video which shows you how to do your normal SQL queries on firebase database. Enjoy

Emeka Obianom
  • 1,736
  • 3
  • 17
  • 36
  • "In Nosql database like firebase you are normally allowed to filter by only 1 field" There are plenty of NoSQL databases that allow filtering on multiple properties.. This is just a Firebase limitation. I'd also recommend reading my answer on filtering on multiple values here: http://stackoverflow.com/questions/26700924/query-based-on-multiple-where-clauses-in-firebase, which covers a few more scenarios than David's video. – Frank van Puffelen Jul 08 '17 at 19:23