Uploaded image for project: 'Documentation'
  1. Documentation
  2. DOCS-4086

How to store local time in MongoDB?

    • Type: Icon: Improvement Improvement
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • v1.3.12
    • Affects Version/s: None
    • Component/s: manual
    • Labels:
      None
    • Environment:
      Casbah driver (Scala) on OS X

      I'm developing my first commercial project using MongoDB. Otherwise very pleased with the quality of the product and documentation, but the corner of handling local times would seriously need more effort, either in the API and/or a tutorial describing good practices.

      StackOverflow.com has multiple cases where people are equally puzzled by this, it's not only me. It should be easy and explicit to:

      • save UTC date and retrieve one, without conversions to the local time zone
      • save local time and retrieve one, as above

      Our customer case is that we want UTC time stamps for the normal reasons, but also wish to see what "wall clock time" and e.g. day of week the stored data fits, in the local context. A tutorial describing how to do this would have helped.

      • should we store local times as BsonDateTime (as if they were UTC)
      • should we store using "minutes from the beginning of the week" (fine grained time would come from the UTC time stamp)
      • should we do something else?

      I think much of the confusion is due to Joda DateTime. I'm considering not using it, later, and dealing with BsonDateTime objects directly. However, for now things are reasonably okay so this must wait.

      Other things being so nice and trivial with MongoDB, how about fixing the local time corner as well?

      Links to StackOverflow issues regarding these:
      http://stackoverflow.com/questions/26023835/how-to-read-back-a-datetime-as-utc-in-mongodb-casbah
      http://stackoverflow.com/questions/16901393/storing-utc-and-local-datetime-in-mongo

            Assignee:
            andrew.aldridge@mongodb.com Andrew Aldridge
            Reporter:
            akauppi Asko Kauppi
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved:
              9 years, 27 weeks, 6 days ago