I have a collection called orders and I want to query it to only show the orders which have the field orderCompleted set to false. However when I use the .where it does not display anything.
orders: Observable<any[]>;
constructor(firestore: AngularFirestore) {
this.orders = firestore.collection('Order', ref=>
ref.where("orderCompleted", "==", false)
.orderBy('collectionTime', 'asc')).valueChanges();
}
You need to create the following inside a service class:
constructor(firestore: AngularFirestore){}
getOrders(){
return firestore.collection('Order', ref=> ref.where("orderCompleted", "==", false).orderBy('collectionTime', 'asc')).valueChanges();
}
Then inside the component, you can inject the service to the constructor of the component class and then subscribe
to the observable
and get the result:
constructor(private service : Service){}
ngOnInit(){
this.service.getOrders().subscribe(data =>{
console.log(data);
});
}