Search code examples
javascriptangulargoogle-cloud-firestoreangularfire2

Why isnt firestore filtering and always returning all documents?


I have the following code and it always retrieves all documents, as if the filter is not being applied. Using angular@5.2.0 and angularfire2@5.0.0-rc.6

loads$: Observable<Load[]>;
status$: BehaviorSubject<string|null>;

this.loads$ = this.status$.switchMap(status => 
    afs.collection<Load>('loads', ref => {
       let query : firebase.firestore.Query = ref;
       query.where('status', '==', status);
       return query;
    }).valueChanges());
});

The database is setup this way https://i.sstatic.net/vOyjL.png

I update the status observable via:

 filterByStatus(status: string) {
    this.status$.next(status); 
  }

Solution

  • I had this code sitting inside a subscription. All I did was moved it over to the component constructor and it started working. Found out I can use combineLatest() to do what I wanted to do.