Query ISODate on MongoDB with Google Sheets “dd-MM-yyyy HH:ss” as an output

。_饼干妹妹 提交于 2019-12-02 04:40:02

You may be able to use the $dateToString aggregation operator inside a $project aggregation stage.

For example:

> db.test.find()
{ "_id": 0, "date": ISODate("2018-03-07T05:14:13.063Z"), "a": 1, "b": 2 }

> db.test.aggregate([
    {$project: {
        date: {$dateToString: {
            format: '%d-%m-%Y %H:%M:%S',
            date: '$date'
        }},
        a: '$a',
        b: '$b'
    }}
])
{ "_id": 0, "date": "07-03-2018 05:14:13", "a": 1, "b": 2 }

Note that although the $dateToString operator was available since MongoDB 3.0, MongoDB 3.6 adds the capability to output the string according to a specific timezone.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!