首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >mongoose如何取两个日期之间的日期

mongoose如何取两个日期之间的日期
EN

Stack Overflow用户
提问于 2021-04-17 20:34:55
回答 1查看 44关注 0票数 0

我有项目租赁应用程序。我需要决定汽车是否在date_finish和date_start之间的日期(包括该日期)。我有模型-汽车和订单。订单有几个字段:dateStartdateFinishcarId How to take only这些在start_date和stop_date之间可用的carIds (包括这两天)。

汽车:

代码语言:javascript
运行
复制
    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' }
)

顺序:

代码语言:javascript
运行
复制
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为存档/完成的订单

mongoose查询:var orders_n = await Order.find({"status":{'$lte':"2"},$and[{"dateFinish":{ '$lte': start},"dateStart":{}}]"dateFinish":{ '$lte': start}}).select('carID -_id').exec();

该查询不起作用。有谁能帮帮我呢?

编辑:我必须(首先)接受这样的订单:开始和结束日期的-date大于用户传递的结束日期-date小于用户传递的开始日期。换句话说,我需要在经过的日期之间的几天内可用的卡。

EN

回答 1

Stack Overflow用户

发布于 2021-04-17 20:45:09

尝试使用以下方式传递日期:var orders_n = await Order.find({"status":{'$lte':"2"},$and[{"dateFinish":{ '$gte': new Date()},"dateStart":{ '$lte': new Date()}}]}).select('carID -_id').exec();

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/67138230

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档