If you are using the default ObjectId
value for your _id
attribute, the creation time is encoded inside it.
As stated in the ObjectID documentation:
ObjectId is a 12-byte BSON type, constructed using:
- a 4-byte value representing the seconds since the Unix epoch,
- a 3-byte machine identifier
- a 2-byte process id, and a 3-byte counter, starting with a random value.
You can call the getTimestamp()
function on an ObjectId
object to get an ISODate
object containing the creation time of the object:
In the mongo shell:
ObjectId().getTimestamp()
ISODate("2014-05-14T14:29:12Z")