I'm doing a web application using Angular 8 and Angularfire. I'm trying to query a collection using two where
with ==
, but, it's not working.
I was following the official guide of querying-collection from Angularfire.
Using this code there is no results at all:
getChats(): Observable<IChatRoom[]> {
return this.afs.collection<IChatRoom>('chats', ref => {
let query: firebase.firestore.CollectionReference | firebase.firestore.Query = ref;
query = query.where('state', '==', 'open');
query = query.where('state', '==', 'transferred');
return query;
}).valueChanges();
}
It works only with one where
, like this:
getChats(): Observable<IChatRoom[]> {
return this.afs.collection<IChatRoom>('chats', ref => {
let query: firebase.firestore.CollectionReference | firebase.firestore.Query = ref;
query = query.where('state', '==', 'open');
return query;
}).valueChanges();
}
I have also tried:
getChats(): Observable<IChatRoom[]> {
return this.afs.collection<IChatRoom>('chats', ref =>
ref
.where('state', '==', 'open')
.where('state', '==', 'transferred')
).valueChanges();
}
My goal is to get all documents in a collection that have the state
field equal to open
or transferred
.