In MongoDB, documents stored in a collection require a unique
_id field that acts as a primary key. MongoDB uses
ObjectIds as the default value for the _id field if the _id
field is not specified; i.e. if a document does not contain a top-level
_id field, the MongoDB driver adds the _id field that holds an
ObjectId. In addition, if the mongod receives a document to
insert that does not contain an _id field, mongod will
add the _id field that holds an ObjectId.

MongoDB clients should add an _id field with a unique ObjectId.
Using ObjectIds for the _id field provides the following additional
benefits:

in the mongo shell, you can access the creation time of
the ObjectId, using the getTimestamp() method.

sorting on an _id field that stores ObjectId values is
roughly equivalent to sorting by creation time.

Important

The relationship between the order of ObjectId
values and generation time is not strict within a single
second. If multiple systems, or multiple processes or threads on
a single system generate values, within a single second;
ObjectId values do not represent a strict insertion order.
Clock skew between clients can also result in non-strict ordering
even for values because client drivers generate ObjectId
values.

Also consider the Documents section for related
information on MongoDB’s document orientation.