【问题标题】:Find records of any date of current month between start date and end date using mongoose使用猫鼬查找开始日期和结束日期之间当月任何日期的记录
【发布时间】:2022-12-10 13:58:13
【问题描述】:

我想查询应该是我选择的月份的记录,它应该在开始日期和结束日期之间。

例如, 我正在存储下面的记录

标题 |开始日期 |结束日期
测试 1 | 2020 年 1 月 11 日 | 01/11/2028
测试 2 | 2018 年 7 月 22 日 | 22/07/2038
测试 3 | 2005 年 5 月 14 日 | 14/05/2035

现在我想查找位于两个开始日期和结束日期之间的当月任何日期的记录。

【问题讨论】:

    标签: node.js mongodb mongoose


    【解决方案1】:
    const d = new Date();
    let cmonth = d.getMonth();
    Model.aggregate([
      {$addFields: {  "month" : {$month: '$startdate'}}},
      {$match: { month: cmonth}}
    ]);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-12-17
      • 1970-01-01
      • 2020-01-05
      • 2014-03-02
      • 1970-01-01
      • 2021-08-05
      相关资源
      最近更新 更多