5

How to create a query CouchDB to retrieve all documents where the size of elements is Greater than X.

This query return all documents where movies.size = 3

{
 "selector": {
  "movies": { "$size": 3}
  }
}

I need to find where movies.size > 3

I'm using CouchDB 2.1.1

Alisson Gomes
  • 1,029
  • 14
  • 30

3 Answers3

0

This isn't supported at the moment in Mango. Altought, it shouldn't be hard to implement. At the moment, you can create a view that index the array lengths. From that, you could use end_key=3 to get document with length lower then 3.

Alexis Côté
  • 3,670
  • 2
  • 14
  • 30
0

if your list is not very long, consider using $or operator:

"$or": [
  {"movies": {"$size": 4}},
  {"movies": {"$size": 5}},
  {"movies": {"$size": 6}},

]
0

This works for version 3.1.1.

{
   "selector": {
      "movies.4": {
         "$exists": true
      }
   }
}

Trivial clarification: the 4 is because of you asked for > 3. If you need >= 3 use movies.3

However, I don't think there is a way to index the elements of an array.

I kept the solution from a MongoDb answerer https://stackoverflow.com/a/15224544/846168

Paolo Sanchi
  • 783
  • 9
  • 19