here is the query
[ { \"$project\": { \"formattedDate\": { \"$dateToString\": { \"format\": \"%Y-%m-%d\", \"date\":
Mongodb 4.0 has introduced $toLong aggregation which convert date to timestamp
db.collection.aggregate([ { "$project": { "createdAt": { "$toLong": "$createdAt" } }} ])
You can try it here