I am querying Firestore in Angular 8, using AngularFire. When I query a string (e.g. module_version
in code below) it works, but trying to query a boolean field in Firestore doesn't work properly with my code below. I can only get all objects with active==true
, but not false
. When I hover the boolean variable active
inside the query (in VSCode) it says "var active: true", instead of "var active: boolean" as I would have expected. I am guessing this is the problem, as I can query true
, but not false
. Hovering the string variable module_version
gives "var module_version: string". (I have read answers to questions about true/false in Javascript, but didn't get any the wiser from this.)
Why does my variable seem to automatically get set to true
and what can I do about it?
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()
)
);
}