ObjectId is a fast-generated and probably unique value that MongoDB uses as a primary key in a collection. It consists of 12 bytes; a timestamp takes the first 4 bytes to record the time when the ObjectId value is created. It is stored in a unique _id field for each document in a collection. This _id field will be automatically generated if it is not declared when a document is injected. On the other hand, ObjectId(<hexadecimal>) is a MongoDB method that we can use to return a new ObjectId value, and to parse an ObjectId value from a string to become an object. Here's an example:
// Pseudo code
var id = '5d2ba2bf089a7754e9094af5'
console.log(typeof id) // string
console.log(typeof ObjectId(id)) // object
In the preceding pseudocode, you can see that we use the getTimestamp method from the object created by the ObjectId method to obtain the timestamp from the ObjectId value. Here's an example:
// Pseudo...