我想获取今年的记录,其中不包含停止状态这里是我的数据。是否有可能通过聚合函数来实现?
这是我的实际数据
{ [
{
shortMovie":"name"
"categrory": "comedy"
"times": [
{
"state": "start",
"date": "2017-1-09T18:30:00.000Z"
},
{
"state": "stop",
"date": "2017-1-09T19:30:00.000Z"
}
],
"_id": "58b017bac8966e17dc59bd95"
}
],[
{
shortMovie":"name"
"categrory": "comedy"
"times": [
{
"state": "start",
"date": "2017-5-09T18:30:00.000Z"
}
],
"_id": "58b017bac8966e17dc59bd95"
}
],
[
{
shortMovie":"name"
"categrory": "comedy"
"times": [
{
"state": "start",
"date": "2017-6-09T18:30:00.000Z"
},
{
"state": "pause",
"date": "2017-6-09T19:30:00.000Z"
},
{
"state": "resume",
"date": "2017-6-09T22:30:00.000Z"
},
{
"state": "stop",
"date": "2017-6-09T23:30:00.000Z"
}
],
"_id": "58b017bac8966e17dc59bd95"
}
]
}
我试过
const startDate = new Date(data.year, 0, 1),
endDate = new Date(data.year, 11, 31, 23, 59, 59, 999),
db.collection.find({$and: [{
$or: [{
"times.0.date": {
$gt: startDate,
$lt: endDate
}
}, {
"times.date": {
$gt: startDate,
$lt: endDate
}
}]
}]}).toarray(function(result){
result.times.map(function(get_time){
})
}