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)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs