DEV Community

Andreas Bergström
Andreas Bergström

Posted on

1

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)

👋 Kindness is contagious

Value this insightful article and join the thriving DEV Community. Developers of every skill level are encouraged to contribute and expand our collective knowledge.

A simple “thank you” can uplift someone’s spirits. Leave your appreciation in the comments!

On DEV, exchanging expertise lightens our path and reinforces our bonds. Enjoyed the read? A quick note of thanks to the author means a lot.

Okay