i have this collection
{ "_id" : ObjectId("57b8277cd48b97d6e38d9eb2"),
"student_id" : "326598",
"sem" : "sem1",
"marks" : [
{
"title" : "english",
"from" : 2,
"to" : 15
},
{
"title" : "maths",
"from" : 5,
"to" : 18
},
{
"title" : "science",
"from" : 10,
"to" : 20
}
]
}
{ "_id" : ObjectId("52873b7e4038253faa4bbc10"),
"student_id" : "124578",
"sem" : "sem1",
"marks" : [
{
"title" : "english",
"from" : 1,
"to" : 20
},
{
"title" : "maths",
"from" : 6,
"to" : 16
},
{
"title" : "science",
"from" : 12,
"to" : 20
}
]
}
and write this query :
var x= 7;
db.getCollection('numbers').aggregate([
{$unwind : "$marks"},
{$match : {$and :[{"marks.from": { $gte :2 } },{"marks.to": { $lte :15 } } ]}}
])
i want return each document contains X value is in range between from and to . for example return document that have X value great than marks.from and less than marsk.to . but that query didnt work.
