ऐसा करने का एक तरीका यह होगा कि aggregation framework
और date aggregation operators
का लाभ उठाएं
. उदाहरण के लिए:
db.camps.aggregate(
[
// Perform the initial match to filter docs by 'status' and 'camp_id'
{
$match:
{
status: 1,
camp_id: pCampID
}
},
// Extract the year, month and day portions of the 'enddate'
{
$project:
{
year: { $year: "$enddate" },
month: { $month: "$enddate" },
day: { $dayOfMonth: "$enddate" },
status: 1,
camp_id: 1
}
},
// Filter by date - Replace hard-coded values with values you want
{
$match:
{
year: { $gte: 2014 },
month: { $gte: 10 },
day: { $gte: 10 }
}
}
]
)