0

How can I query data in AngularFirestoreCollection using where()? Here's what I have tried but to no avail. What I want is to display the current user's tasks when logged in.

Firestore: database

import { AngularFirestore, AngularFirestoreCollection } from '@angular/fire/firestore';
import { Observable } from 'rxjs';
import { AngularFireAuth } from '@angular/fire/auth';

export interface Tasks {
  title: string;
  description: string ;
}

@Injectable({
    providedIn: 'root'
  })

export class getData {

private taskCollection: AngularFirestoreCollection<Tasks>;
private task: Observable<Tasks[]>;

constructor(
  private afs: AngularFirestore,
  private afAuth: AngularFireAuth
) {
  var getid = afAuth.auth.currentUser;

  this.taskCollection = afs.collection<Tasks>('taskList', 
  ref => ref.where('user', '==', getid))

   this.task = this.taskCollection.snapshotChanges().pipe(
    map(actions => {
      return actions.map(a => {
        const data = a.payload.doc.data();
        const id = a.payload.doc.id;
        return { id, ...data};
      });
    })
  );
 }
}

However, when I check the console I'm getting an error: ERROR Error: Uncaught (in promise): FirebaseError: [code=invalid-argument]: Function Query.where() called with invalid data. Unsupported field value: a custom P object.

Reference : https://stackoverflow.com/a/50958131/6385659

CODEr
  • 33
  • 1
  • 5

0 Answers0