Skip to content

Update create-a-unique-index.txt #1655

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions source/tutorial/create-a-unique-index.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,15 @@ The :ref:`_id index <index-type-id>` is a unique index. In some
situations you may consider using ``_id`` field itself for this kind
of data rather than using a unique index on another field.

The unicity constraint prevents two documents from the collection to
have the same value, but it does not prevent one specific document to
have a value duplicated. For instance, a unique index on ``a.b``
will let the following document exist:

.. code-block:: javascript

{ "a" : [ { "b": 1 }, { "b" : 1 } ] }

In many situations you will want to combine the ``unique`` constraint
with the ``sparse`` option. When MongoDB indexes a field, if a
document does not have a value for a field, the index entry for that
Expand Down