Format date in mongodb query output on shell

前端 未结 1 981
孤街浪徒
孤街浪徒 2021-01-18 02:50

I want to format the date time into an specific format on the mongo shell output

My query

db.getCollection(\'people\').find({
        date: { 
               


        
1条回答
  •  太阳男子
    2021-01-18 03:41

    Solution is using aggregation pipeline as stated by Veeram in comments section

    db.getCollection('people').aggregate([
        {
            $project:{
                datetime: {$dateToString: {format: "%G-%m-%d %H:%M:%S",date: "$datetime"}},
                age : 1
            }
        }
    ]);
    

    0 讨论(0)
提交回复
热议问题