dappsnation / akita-ng-fire

Akita ❤️ Angular 🔥 Firebase
MIT License
131 stars 27 forks source link

How to sync only a subset of a collection? #206

Closed jaytonic closed 3 years ago

jaytonic commented 3 years ago

Hi,

I've a collection of documents where people can add documents, and add participants to a document.

I need my AAAAQuery/Service/Store to only applies to documents where my current angular fire auth user Id is contained in the dictionary of string "participants" of each object.

My understanding is that I should be able to call some "sync" method on the service, that will make a request with some parameters to filter the collection, but I can't find an example of that.

I'm sure it is possible, but not sure how?

Here are document in my /plannings/{id}

export interface Planning{
  id?: string;
  name: String;
  date: Date;
  manager: string;
  participants: string[];
}
GrandSchtroumpf commented 3 years ago

Best would be to do a simple query :

export class PlanningComponent {
  plannings$ = this.auth.authState.pipe(
    switchMap(user => this.service.valueChanges(ref => ref.where('participants', 'array-contains', auth.uid)))
  );

  constructor(
    private service: PlanningService,
    private auth: AngularFireAuth,
  ) {}
}