0

I have a collection that contains a dateTime field that in String format:

{
    "dateTime" : "04/09/2018 13:24:35 EDT"
}

Now I need to change the field to a different dataTime format:

{
    "dateTime" : "2018-04-09 13:24:35 EDT"
}

What is the best way to do this?

user2777473
  • 3,736
  • 5
  • 26
  • 39
  • 3
    It is a bad idea to store a date as a string. Store it as date, and format it the way you need it in the presentation layer. – Markus W Mahlberg May 07 '18 at 19:30
  • A very bad bad idea. BSON Dates are what you want. If you think you want "local time" then think again, because every reason you think you have will actually be wrong. All "updates" in reality do require you to "loop" the collection in order to read each value and write back each individually, unless you can actually get away with creating a new collection and that answer is not changing anytime soon. Follow the answers that have been around for years and also follow the common wisdom and learn to use the BSON date. – Neil Lunn May 07 '18 at 21:18

0 Answers0