views:

71

answers:

2

What's the best way to store timestamps in MongoDB?

  1. Which format is best:

    # "created": { "d" : "2010-03-29", "t" : "20:15:34" }
    # "created": "12343545234" # seconds since epoc
    # "created": "2010-03-14T21:20:14+0000"
    
  2. Is there a way to have MongoDB automatically set created and updated fields?

Thanks!

Matt

+1  A: 

Which format is best

Best for what?

Is there a way to have MongoDB automatically set created and updated fields?

Created time is in the ObjectId but, as far as I know, you will have to update a updated field manually.

Jonas Elfström
+1  A: 
  1. The format you need to process it with best performance in your application should be preferred. Note that as default every document in MongoDB gets a created timestamp (http://www.mongodb.org/display/DOCS/Object+IDs#ObjectIDs-DocumentTimestamps)

  2. See 1) + I think you need to manually set the "update" field.

halfdan
MattDiPasquale