Reputation: 2037
this is my database: firebase database
I want to retrieve a dish that its 'featured' attribute is true (dish.feature = true).
is it possible? or I have to retrieve all dishes and query it on client side??
Upvotes: 1
Views: 789
Reputation: 38827
You can use a combination of orderByChild
and equalTo
to achieve this using AngularFire2 querying lists:
db.list('/dishes', ref => ref.orderByChild('featured').equalTo(true))
The examples uses db
for the injected instance of AngularFireDatabase
, you would replace that with whatever you named your injected instance in the controller of your component executing the query.
@Component({ ... })
export class FooComponent {
constructor(db: AngularFireDatabase) {}
}
Update:
You may receive a warning indicating an .indexOn
needs to be added to your Firebase database rules. At the most basic level it would look like this:
{
"rules": {
"dishes": {
".indexOn": ["featured"]
}
}
}
Hopefully that helps!
Upvotes: 2