Vivendo
Vivendo

Reputation: 71

Get/filter documents based on field id

I have around 20 documents in the Firebase database which each have fields with an "id" with a value. How does one query the database to get/filter to return every document with a specific "id" and omit the rest?

Upvotes: 2

Views: 978

Answers (1)

Balaj Khan
Balaj Khan

Reputation: 2570

You can filter data by id by below query:

this.firestore.collection("collectionName", res => res.where('userId', '==', yourId))
   .snapshotChanges().pipe(map(list => {
       return list.map(item => {
          return {id: ...item.payload.doc.id, ...item.payload.doc.data()}
       })
   })).subscribe(data => {
      console.log(data);
   });

Upvotes: 1

Related Questions