饮歌长啸
mongodbDateAggregationOperators文档地址:https://docs.mongodb.com/manu...$dateToString这个需要mongodb3.0以上才支持源数据db.getCollection('devices').insert([{"_id":ObjectId("593d1df123aa5c000ea57b80"),"Last_Modify_Time":1.0,"Last_Modify_By":1.0,"Creation_Time":ISODate("2017-06-11T10:39:45.000Z")},{"_id":ObjectId("593e7091e2bdc3000e4cdca3"),"Last_Modify_Time":2.0,"Last_Modify_By":2.0,"Creation_Time":ISODate("2017-06-12T10:44:33.000Z")},{"_id":ObjectId("5949106bd4e170000e544c1a"),"Last_Modify_Time":3.0,"Last_Modify_By":3.0,"Creation_Time":ISODate("2017-06-20T12:09:15.000Z")},{"_id":ObjectId("593ced72c4162e000e7e9611"),"Last_Modify_Time":null,"Last_Modify_By":null,"Creation_Time":ISODate("2017-06-11T07:12:50.000Z")}])SQL语句db.getCollection('devices').aggregate([{$project:{'date':{//将Creation_Time字段加上8*60*60*1000毫秒后,再格式化时间$dateToString:{format:"%Y-%m-%d%H:%M:%S",date:{$add:['$Creation_Time',28800000]}}},'Last_Modify_Time':'$Last_Modify_Time','Last_Modify_By':'$Last_Modify_By'}}])结果/*1*/{"_id":ObjectId("593d1df123aa5c000ea57b80"),"Last_Modify_Time":1.0,"Last_Modify_By":1.0,"date":"2017-06-1118:39:45"}/*2*/{"_id":ObjectId("593e7091e2bdc3000e4cdca3"),"Last_Modify_Time":2.0,"Last_Modify_By":2.0,"date":"2017-06-1218:44:33"}/*3*/{"_id":ObjectId("5949106bd4e170000e544c1a"),"Last_Modify_Time":3.0,"Last_Modify_By":3.0,"date":"2017-06-2020:09:15"}/*4*/{"_id":ObjectId("593ced72c4162e000e7e9611"),"Last_Modify_Time":null,"Last_Modify_By":null,"date":"2017-06-1115:12:50"}