Reputation: 7269
I have this structure:
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: '[email protected]',
key: 'from'
}
}
});
This gives nothing: empty array. Why?
And another question is: how to I can filter items by 2 fields? I need [email protected]&status=ACCEPTED
for example.
How it is possible to do it with FB?
Upvotes: 1
Views: 3509
Reputation: 1794
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: '[email protected]',
}
});
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
Upvotes: 2