2

I need to get the documents where exists Archery in the array list of games. How can i do with CouchDB selector?

[{
    "name": "John",
    "games": ["Archery", "Board sports"]
},
{
    "name": "Sara",
    "games": ["Fishing", "Archery"]
},
{
    "name": "Tara",
    "games": ["Decathlon"]
}]
Sebastián
  • 95
  • 1
  • 8
  • Possible duplicate of [Cloudant Selector Query for fetching particular elements inside Array](https://stackoverflow.com/questions/45460879/cloudant-selector-query-for-fetching-particular-elements-inside-array) – Jonathan Hall Mar 14 '19 at 18:31

1 Answers1

3

You can use $elemMatch:

{
   "selector": {
      "games": {
         "$elemMatch": {
            "$eq": "Archery"
         }
      }
   }
}

It will return all objects where games field equals 'Archery'

Rouliboy
  • 1,377
  • 1
  • 8
  • 21