我们说我的下面有一个事件架构
eventSchema = new Schema({
name: { type: String },
startDate: {type: Date },
endDate: {type: Date }
});
我有一组数据:
{ name: 'Event 1'
startDate: '2017-06-23 09:58:03.759Z'
endDate: '2017-07-02 09:58:03.759Z'
},
{ name: 'Event 2'
startDate: '2017-07-05 09:58:03.759Z'
endDate: '2017-07-10 09:58:03.759Z'
}
{ name: 'Event 3'
startDate: '2017-07-23 09:58:03.759Z'
endDate: '2017-08-01 09:58:03.759Z'
}
{ name: 'Event 4'
startDate: '2017-08-03 09:58:03.759Z'
endDate: '2017-08-05 09:58:03.759Z'
}
如何编写查询以查找2017-07-01至2017-07-31期间发生的事件?
这意味着我需要获取事件1,2和3的数据集。
这是我到目前为止所做的:
Event.find({
$and: [
{ startDate: { $gte: start } },
{ endDate: { $lte: end } },
]
}, (err, events) => {
if (err) return next(err);;
res.send({ success: true, events: events });
});