DEV Community

Andreas Bergström
Andreas Bergström

Posted on

Convert string dates to Date-type in MongoDB

If you ever run into MongoDB-collections with documents having date fields that are of type String instead of Date, just use this query:

db.collection.updateMany( {created: {$type: ”string”}}, [{ $set: { created: { $toDate: ”$created” }}}] )

Top comments (0)