Skip to content

DOCS-9120: emphasize BSON limit on distinct, propose agg alternative #3213

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

Merged
merged 1 commit into from
Feb 1, 2018
Merged
Show file tree
Hide file tree
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
8 changes: 8 additions & 0 deletions source/includes/note-distinct-bson-limit-agg-alternative.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
.. note::

Results must not be larger than the maximum :ref:`BSON size
<limit-bson-document-size>`. If your results exceed the maximum
BSON size, use the aggregation pipeline to retrieve distinct
values using the :pipeline:`$group` operator, as described in
:ref:`Retrieve Distinct Values with the Aggregation Pipeline
<aggregation-group-distinct-values>`.
7 changes: 7 additions & 0 deletions source/includes/table-sql-to-mongo-select-examples.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,13 @@ sql19: |
SELECT DISTINCT(status)
FROM people
mongo19: |
.. code-block:: javascript
:emphasize-lines: 1

db.people.aggregate( [ { $group : { _id : "$status" } } ] )

or, for distinct value sets that do not exceed the :ref:`BSON size limit <limit-bson-document-size>`

.. code-block:: javascript
:emphasize-lines: 1

Expand Down
4 changes: 3 additions & 1 deletion source/reference/command/distinct.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,11 @@ Definition

.. include:: /includes/apiargs/dbcommand-distinct-field.rst

.. include:: /includes/note-distinct-bson-limit-agg-alternative.rst

MongoDB also provides the shell wrapper method
:method:`db.collection.distinct()` for the :dbcommand:`distinct`
command. Additionally, many MongoDB :term:`drivers <driver>` also
command. Additionally, many MongoDB :term:`drivers <driver>`
provide a wrapper method. Refer to the specific driver documentation.

Behavior
Expand Down
5 changes: 3 additions & 2 deletions source/reference/method/db.collection.distinct.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@ Definition
.. include:: /includes/apiargs/method-db.collection.distinct-param.rst

The :method:`db.collection.distinct()` method provides a wrapper
around the :dbcommand:`distinct` command. Results must not be larger
than the maximum :ref:`BSON size <limit-bson-document-size>`.
around the :dbcommand:`distinct` command.

.. include:: /includes/note-distinct-bson-limit-agg-alternative.rst

.. _distinct-method-options:

Expand Down