Javascript 日期冲突的猫鼬查找
我有一个猫鼬模型,它保存一个事件的开始和结束日期 我想要一个以开始和结束日期为参数的查询,看看它是否与数据库中的任何事件冲突 比如:Javascript 日期冲突的猫鼬查找,javascript,mongodb,mongoose,nosql,Javascript,Mongodb,Mongoose,Nosql,我有一个猫鼬模型,它保存一个事件的开始和结束日期 我想要一个以开始和结束日期为参数的查询,看看它是否与数据库中的任何事件冲突 比如: 'select where' - endDate < currentBooking.endDate && startDate < currentBooking.startDate) || end > currentBooking.endDate && startDate > currentBooki
'select where' -
endDate < currentBooking.endDate && startDate < currentBooking.startDate) || end > currentBooking.endDate && startDate > currentBooking.startDate
“选择位置”——
endDatecurrentBooking.endDate&&startDate>currentBooking.startDate
但我怎么能把它写成猫鼬查询呢 请对此进行测试,希望这能解决您的问题
Ebook.find({
$or: [{
$and: [{ endDate: { $lte: currentBooking.endDate } }, { startDate: { $lte:
currentBooking.startDate}}],
$and: [{ endDate: { $gte: currentBooking.endDate } }, { startDate: { $gte:
currentBooking.startDate}}]
}]
},function(err, data) {
if (err)
res.send(err);
res.json(data);
});
});
Atiq Ur Rehman直接翻译了您的查询,但为了确保这一点,您还必须包含满足以下条件的事件:
endDatecurrentBooking.startDate
。