これを行う1つの方法は、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 }
}
}
]
)