I have a MongoDB collection with the following data:
{
"_id" : "8BDAbpoqXYpWGgy24", // String
"date" : "2013-03-19" // String
}
Is there a way to convert the date field to a timestamp value (ISODate)?
You can try using below $toLong and $dateFromString aggregations
db.collection.aggregate([
{
"$project": {
"date": {
"$toLong": {
"$dateFromString": {
"dateString": "$date"
}
}
}
}
}
])
You can try it here