Sebastián
Sebastián

Reputation: 95

CouchDB query selector on string in array of elements

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"]
}]

Upvotes: 2

Views: 1232

Answers (1)

Rouliboy
Rouliboy

Reputation: 1377

You can use $elemMatch:

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

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

Upvotes: 3

Related Questions