I am querying a firestore (7.5.0) db from angular (14.2). The where clause(s) allow only one range/inequality predicate, so I am trying to use filter to affect the second. This code
let project$: Observable<Project[]> = this.firestore.collection<Project>('Projects',
ref => ref.where('EndDt', '>=', startDt)).
valueChanges().pipe(filter((proj) => { // Gets whole array once so all or nothing
console.log('proj: ', proj) ;
return proj['StartDt'] <= endDt ;
})) ;
Sends filter the entire result (110 documents) all at once so my true or false return seems like an all or nothing (I could iterate thru the array … but again it’s all or nothing). Am I structuring this wrong? Thanks,
>Solution :
The RxJs filter operator does not filter the response, it filters the stream. If a value passes the filter function then the stream emits the value other wise the stream doesn’t emit. If you want to filter the results you need to use the RxJs map operator to transform the emitted value and use the filter on the emitted array.
obs$.pipe(map(results => results.filter(val => filterFunction(val))));