I am learning Angular and trying to use Firestore through angular2-firestore. I created 2 collections structured as this:
export interface Account {
uid: string;
title: string;
startDate: Date;
endDate: Date;
manager: User;
members: User[];
}
export interface User {
uid: string;
email: string;
displayName: string;
isActive: boolean;
}
Now I need to query accounts by a user who is member in it. What I could do is fetch all of the accounts and then filter them using Typescript code, but I thought there should be some more efficient way to do this. Anybody please help. Thanks in advance.
Update
In my service, I added a method like this:
@Injectable()
export class AccountService {
private static ACCOUNTS_TABLE_NAME = 'accounts';
constructor(private db: AngularFirestore) {
}
public getAllOpenAccountsIAmIn(user: User) {
return this.db.collection(AccountService.ACCOUNTS_TABLE_NAME, ref => {
return ref.where('endDate', '==', null)
// .where('members', 'contains', user); -- this is what I want something like
}).valueChanges();
}
}