How to store timestamps? Are created and updated fields available automatically?
If you do following on mongo shell it shows you time stamp that represents when that documents inserted using mongoId. For ex. ObjectId("51f3dee5ee49f9b91e0db133").getTimestamp()
, then it returns ISODate
.
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()
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)
See 1) + I think you need to manually set the "update" field.