Skip to content

Commit

Permalink
DOCS-5704 clarify who creates ObjectId
Browse files Browse the repository at this point in the history
  • Loading branch information
kay-kim committed Jun 25, 2015
1 parent 3e36b97 commit 3a5b94d
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions source/reference/object-id.txt
Expand Up @@ -18,16 +18,17 @@ constructed using:
- a 3-byte counter, starting with a random value.

In MongoDB, documents stored in a collection require a unique
:term:`_id` field that acts as a :term:`primary key`. Because
ObjectIds are small, most likely unique, and fast to generate, MongoDB
uses ObjectIds as the default value for the ``_id`` field if the
``_id`` field is not specified. MongoDB clients should add an ``_id``
field with a unique ObjectId. However, if a client does not add an
``_id`` field, :program:`mongod` will add an ``_id`` field that holds
an ObjectId.

Using ObjectIds for the ``_id`` field provides the following
additional benefits:
:term:`_id` field that acts as a :term:`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 :program:`mongod` receives a document to
insert that does not contain an ``_id`` field, :program:`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 :program:`mongo` shell, you can access the creation time of
the ``ObjectId``, using the :method:`~ObjectId.getTimestamp()` method.
Expand All @@ -41,8 +42,8 @@ additional benefits:
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, *not* the :program:`mongod` process.
even for values because client drivers generate ``ObjectId``
values.

Also consider the :doc:`/core/document/` section for related
information on MongoDB's document orientation.
Expand Down

0 comments on commit 3a5b94d

Please sign in to comment.