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 } } )