Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

filter rxjs operator on result valuechanges

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,

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>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))));
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading