big papa
big papa

Reputation: 47

Firebase - Is there a way to get only documents with an array field which contains a certain value?

If I have a simple collection Cats:

Cats:
  Meowy:
    colors: ['orange', 'white']
  Purro:
    colors: ['black', 'orange']
  Bob:
    colors: ['black']

How can I query only the documents that their colors field contains orange (in JavaScript)?

Upvotes: 1

Views: 69

Answers (1)

giraycoskun
giraycoskun

Reputation: 161

This seems it can work however I haven't tried in my local. Also check the firebase documentation :

https://firebase.google.com/docs/firestore/query-data/queries#web_3

var catRef = db.collection("Cats");

catRef.where('colors', 'array-contains',
    'orange');

Upvotes: 1

Related Questions