【问题标题】:node js compare mongodb database time and current time of a servernode js比较mongodb数据库时间和服务器的当前时间
【发布时间】:2019-10-18 21:25:35
【问题描述】:

如果存储在 mongodb 数据库中的日期早于当前系统/服务器时间,我有下面的代码将 offer_status 更新为“过期”;

dbo.collection("offers").updateMany({older_date_in_DB:{$lt: current_system_time},
     {$set: 
     {offerStatus:"EXPIRED"}},
     (err,response)=>{
        if(err) throw err;
        console.log(response.modifiedCount)
    })

但是,我注意到如果当前日期是 2019 年 10 月 18 日,而 old_date_in_db 是 2019 年 8 月 1 日,则上述查询不会将报价状态更新为“已过期”。我不明白为什么? 像 2019 年 10 月 15 日这样的日期会将状态更新为“已过期”,而像“2019 年 8 月 1 日”这样的日期不会。

【问题讨论】:

    标签: node.js mongodb


    【解决方案1】:

    请使用以下行在 mongodb 中比较日期条件

     { older_date_in_DB: { $lt: new Date('10/18/2019') } }
    

    如果 value 是 dateFormat 则使用 new 关键字

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-02-24
      • 1970-01-01
      • 2013-01-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多