node.js - 考虑所有可能性,在猫鼬中的两个值之间进行查询
问题描述
所以,我不知道如何描述一个问题的问题,所以这里是一个例子:
假设我需要退房 我需要在这个给定时间预约:开始时间:8,结束时间:11
但是,这些是无法完成预约的可能性:
There's an appointment at 9 and it ends at 11; -- can't be done
There's an appointment at 8 and it ends at 10; -- can't be done
There's an appointment at 9 and it ends at 10; -- can't be done
There's an appointment at 7 and it ends at 12. -- can't be done
对于前三种可能性,我确实对如何进行查询有所了解;但是,对于最后一种可能性,我没有。我是使用猫鼬的新手,所以我真的不知道如何完成它。提前致谢。
解决方案
db.collection.find({
"$and": [
{
"start": {
"$lte": 11
}
},
{
"end": {
"$gte": 8
}
}
]
})/**8,11*/
我只是添加了基于
t1 = [8,10]
t2 = [8,11]
isBefore = !t1.end.isBefore(t2.begin)
&& !t1.begin.isAfter(t2.end);
推荐阅读
- python - 如何将多个列表值作为函数参数传递?
- java - 如何从一个用户在android firebase中发布的所有帖子中获取总点赞数?
- c# - EXE的不同文件夹中的DLL库(相对路径)
- javascript - 有没有比 setTimeout(0) 更快的方式让 Javascript 事件循环?
- php - 如何修复 kartik\dynagrid\DynaGrid 中的 filterModel 错误?
- php - 为什么异或结果不一样,0变成1
- python - 在 Robot 框架中修改具有硬编码参数的用户定义关键字
- reactjs - ReactJS Iframe 未加载页面
- java - 如何在 Android 中移动到第二个布局?
- python - 我如何从 bs4 在 python 中选择这个元素