Alex Rivera | Logout

How to store timestamps? Are created and updated fields available automatically?

Asked 2010-09-16T13:46:33.123
23

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?

Edit
Report

1 Answer

26

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.

Example:

ObjectId("538141a9615760fd04ffef5f").getTimestamp()
answered 2010-09-16T13:53:35.910

Your Answer