Database

[{ "_id": "1", "device_id": "ML39A-341D4-UI041", "date": "2018-03-28T00:00:00.000Z" }, { "_id": "2", "device_id": "ML39A-341D4-UI041", "date": "2018-03-29T00:00:00.000Z" }, { "_id": "3", "device_id": "D4YK2-R2D20-KYPI9", "date": "2018-04-01T00:00:00.000Z" } ]

Query

db.collection.aggregate([{ "$group": { "_id": "$device_id", "dt": { "$push": "$date" } } }, { "$replaceRoot": { "newRoot": { "$arrayToObject": { "$concatArrays": [ [{ "k": "$_id", "v": "$dt" }] ] } } } }])

Result