mongo db querying array values with greater and less than mongo db querying array values with greater and less than arrays arrays

mongo db querying array values with greater and less than


Use $elemMatch to constrain both parts of the range query to the same marks element:

db.users.count({    marks: {$elemMatch: {$gte: 20, $lt: 30}}})


Isn't it just this:

db.scores.count( { 'marks' : { '$gt' : min_value , '$lt' : max_value } } )

Which in your case would translate to:

db.scores.count( { 'marks' : { '$gt' : 20 , '$lt' : 30 } } )


db.scores.count(   { marks: { $elemMatch: { $gte: 20, $lt: 30} } })

For more information refer https://docs.mongodb.com/manual/reference/operator/query/elemMatch/