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: '[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?

1 Answer 1

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: '[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

Sign up to request clarification or add additional context in comments.

1 Comment

"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: stackoverflow.com/questions/26700924/…, which covers a few more scenarios than David's video.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.