Convert MongoDB ObjectId to Timestamp



Result :- 2018-03-01T18:30:00.000Z
Use only for comparisons, not for creating new documents as this is not unique.

The ObjectId class is the default primary key for a MongoDB document and is usually found in the _id field in an inserted document.

Using ObjectId you can find the document creation time because timestamp is hidden in the ObjectId.

ObjectId contain the following:

Size Description
4 bytes a 4-byte value representing the seconds since the Unix epoch
3 bytes a 3-byte machine identifier
2 bytes 2-byte process id
3 bytes 3-byte counter, starting with a random value

Complete HTML:

Hi! I am Sartaj Husain. I am a Professional Software Developer, live in Delhi. I write blogs in my free time. I love to learn and share the knowledge with others because it is no good to try to stop knowledge from going forward. So free posts and tutorials. more..

No comments