Mongodb 文檔時間字段修改


mongo文檔【tblEvent】如下:

{
    "_id" : ObjectId("5a0415f9bf28b684b1c7f5b2"),
    "citycode" : 3501,
    "startTime" : ISODate("2016-01-02T00:00:00.000+0800"),
    "endTime" : ISODate("2016-12-31T23:59:00.000+0800"),
    "eType" : 2,

}

給文檔startTime加一天:

db.tblEvent.find().forEach(
   function(item){                
       db.tblEvent.update({"_id":item._id},{"$set":{"startTime":new Date(item.startTime.getTime() + 1*24*60*60000)}},false,true)
     }
)

其中:

1 day = 1*24*60*60000 = 1 x 24 hours x 60 minutes x 60 seconds x 1000 milliseconds


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM