convert iso date to timestamp in mongo query

Mongodb 4.0 has introduced $toLong aggregation which convert date to timestamp

db.collection.aggregate([
  { "$project": {
    "createdAt": {
      "$toLong": "$createdAt"
    }
  }}
])

You can try it here

Leave a Comment