javascript - 猫鼬如何在两个之间约会
问题描述
我有项目 - 租赁应用程序。我需要确定在 date_finish 和 date_start 之间的日期(包括该日期)是否有汽车可用。我有模型 - 汽车和订单。订单的字段很少:dateStart
以及dateFinish
,carId
如何仅获取 start_date 和 stop_date 之间(包括这 2 天)之间可用的这些 carId。
车:
mark:{
type: String,
required: true,},
model:{
type: String,
required: true,},
price:{
type: Number,
required: true,},
available: {
type: Boolean,
required: true,},
pic_1:{
type:String,
required:true,
},
pic_2:{
type:String,
required:true,
},
},
{ collection: 'cars' }
)
命令:
const orderSchema = new mongoose.Schema(
{
userID: { type: String, required: true },
carID: { type: String, required: true },
status: {type:String,required:true},
dateStart: {type:Date,required:true},
dateFinish:{type:Date,required:true},
total: {type:Number,required:true},
},
{ collection: 'orders' }
)
状态:1 个新订单,2 个当前订单,3 个存档/已完成订单
猫鼬查询:
var orders_n = await Order.find({"status":{'$lte':"2"},$and[{"dateFinish":{ '$lte': start},"dateStart":{}}]"dateFinish":{ '$lte': start}}).select('carID -_id').exec();
该查询不起作用。谁能帮我?
编辑:我必须(首先)接受以下订单: - 开始日期和结束日期大于用户结束日期所传递的 - 结束日期低于用户开始日期所传递的。换句话说 - 我需要在过去日期之间的几天内可用的卡片。
解决方案
以这种方式尝试通过日期:var orders_n = await Order.find({"status":{'$lte':"2"},$and[{"dateFinish":{ '$gte': new Date()},"dateStart":{ '$lte': new Date()}}]}).select('carID -_id').exec();
推荐阅读
- angular - 基于 Angular 教程的 Visual Studio 代码调试不起作用
- rust - 如何使用包含返回对 Self 的引用的方法的 trait 对象?
- r - 一种用户将选择存储为输入以供以后使用的方法
- powershell - 使用正则表达式数组 (regex) 过滤文件列表
- html - 在 SQL 中创建 HTML 无序列表
- php - 在 PHP 中设置环境变量适用于一个用户,但不适用于另一个用户
- c# - AWS S3 获取对象部分元数据
- html - 文本未显示,背景颜色和文本颜色不同
- mysql - 将 ExpressJS MySql 查询响应发送到一个简单的 JS 文件以编辑 HTML 表
- c# - 为什么我的 Unity CharController Dash 函数没有将我推向正确的方向,尽管看起来正确的值..?