I have a collection named students
containing the following documents
{_id: 1, marks:[1,2,3,4,5]}
{_id: 2, marks:[4,2,6,4,5]}
{_id: 3, marks:[9,6,3,4,5]}
{_id: 4, marks:[6,2,2,4,7]}
{_id: 5, marks:[7,2,2,4,7]}
I want to get those documents where the value of first element of the marks array is between 3 and 8 . I am using following $expr based aggregate query. But it is returning no document. Please note I want to use $expr only.
db.students.aggregate([{
$match: {
$expr: {
“$and”: [{
“$gte”: ["$marks.0", 3]
}, {
“$lte”: ["$marks.0", 8]
}]
}
}
}])
Please help. Thanks in advanced.