Update the date format on all documents

Hello!

I migrated a old sql database over to Mongodb. However, the dates there looks like this.

[
{title:"hello world", dateFrom:"2017-05-19 00:00:00",dateTo:null},
{title:"hello whirl", dateFrom:"2017-05-17 00:00:00",dateTo:"2017-05-17 00:00:00"}
]

Is there a query or so that can automatically update the dateformats to be ISODate format (which I think is the standard mongodb use?)

Something like:

db.collection.update({},
[
  {
    $set: {
      dateTo: {
        $toDate: "$dateTo"
      },
      dateFrom: {
        $toDate: "$dateFrom"
      }
    }
  }
])
2 Likes

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.