I would like fetch the records of this year, which is not containing stop state here is my data. Is it possible to achieve by aggregate function?
this is my actual data
{ [
{
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"
}
]
}
i tried
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){
})
}