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}}})
db.scores.count( { marks: { $elemMatch: { $gte: 20, $lt: 30} } })
For more information refer https://docs.mongodb.com/manual/reference/operator/query/elemMatch/