Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

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?

like image 810
ma11hew28 Avatar asked Sep 16 '10 13:09

ma11hew28


1 Answers

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() 
like image 86
Jonas Elfström Avatar answered Sep 28 '22 04:09

Jonas Elfström