請問日期查詢問題


  • 註冊用戶

    請問可以查詢 Document 中的字串欄位, 以日期區間查詢嗎? 

    案例如下:

    db.timelog.insert({"starttime":"2017-02-01T10:11:57.768+08:00","endtime":"2017-02-01T10:13:57.768+08:00","logid":1}); 
    db.timelog.insert({"starttime":"2017-02-02T10:11:57.768+08:00","endtime":"2017-02-02T10:13:57.768+08:00","logid":2}); 
    db.timelog.insert({"starttime":"2017-02-03T10:11:57.768+08:00","endtime":"2017-02-03T10:13:57.768+08:00","logid":3}); 
    db.timelog.insert({"starttime":"2017-02-04T10:11:57.768+08:00","endtime":"2017-02-04T10:13:57.768+08:00","logid":4});
    db.timelog.insert({"starttime":"2017-02-05T10:11:57.768+08:00","endtime":"2017-02-05T10:13:57.768+08:00","logid":5});
    db.timelog.insert({"starttime":"2017-02-06T10:11:57.768+08:00","endtime":"2017-02-06T10:13:57.768+08:00","logid":6}); 
    db.timelog.insert({"starttime":"2017-02-07T10:11:57.768+08:00","endtime":"2017-02-07T10:13:57.768+08:00","logid":7});
    

    查詢 starttime 在 2017-02-02 至 2017-02-05 之間的資料, 有辦法查詢嗎?


  • 註冊用戶

    db.timelog.insert({"starttime":ISODate("2017-02-01 00:00:00")});
    db.timelog.insert({"starttime":ISODate("2017-02-02 00:00:00")});
    db.timelog.insert({"starttime":ISODate("2017-02-03 00:00:00")});
    db.timelog.insert({"starttime":ISODate("2017-02-04 00:00:00")});
    db.timelog.insert({"starttime":ISODate("2017-02-05 00:00:00")});
    db.timelog.insert({"starttime":ISODate("2017-02-06 00:00:00")});

    db.timelog.find({
     starttime: {
         $gte: ISODate("2017-02-02 00:00:00"),
         $lt: ISODate("2017-02-05 00:00:00")
     }


登录后回复
 

与 萌阔论坛 的连接断开,我们正在尝试重连,请耐心等待