Currently, I am facing an issue with querying Firestore in Angular 8 using AngularFire. While querying a string like module_version
works perfectly fine as shown in the code snippet below, the problem arises when attempting to query a boolean field in Firestore. The issue is that my code seems to only retrieve objects where active==true
, failing to fetch those with false
. Interestingly, when I hover over the boolean variable active
within the query (in VSCode), it displays "var active: true" instead of "var active: boolean." This disparity likely explains why I can query true
but not false
. On the other hand, hovering over the string variable module_version
reveals "var module_version: string". Despite reading up on similar questions about true/false handling in Javascript, I remain unclear on how to address this dilemma.
Why does my variable appear to default to true
, and what steps can I take to rectify this misunderstanding?
constructor(afs: AngularFirestore) {
this.activeFilter$ = new BehaviorSubject(null);
this.module_versionFilter$ = new BehaviorSubject(null);
this.modules$ = combineLatest(
this.activeFilter$,
this.module_versionFilter$
).pipe(
switchMap(([active, module_version]) =>
afs.collection<Module>('Modules', ref => {
let query : firebase.firestore.CollectionReference | firebase.firestore.Query = ref;
if (active) { query = query.where('active', '==', active) };
if (module_version) { query = query.where('module_version', '==', module_version) };
return query;
}).valueChanges()
)
);}