Skip to content

Commit 00a3e5b

Browse files
schmallisokay-kim
authored andcommitted
DOCS-9120: emphasize BSON limit on distinct, propose agg alternative
1 parent 87586a1 commit 00a3e5b

File tree

4 files changed

+21
-3
lines changed

4 files changed

+21
-3
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
.. note::
2+
3+
Results must not be larger than the maximum :ref:`BSON size
4+
<limit-bson-document-size>`. If your results exceed the maximum
5+
BSON size, use the aggregation pipeline to retrieve distinct
6+
values using the :pipeline:`$group` operator, as described in
7+
:ref:`Retrieve Distinct Values with the Aggregation Pipeline
8+
<aggregation-group-distinct-values>`.

source/includes/table-sql-to-mongo-select-examples.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,13 @@ sql19: |
343343
SELECT DISTINCT(status)
344344
FROM people
345345
mongo19: |
346+
.. code-block:: javascript
347+
:emphasize-lines: 1
348+
349+
db.people.aggregate( [ { $group : { _id : "$status" } } ] )
350+
351+
or, for distinct value sets that do not exceed the :ref:`BSON size limit <limit-bson-document-size>`
352+
346353
.. code-block:: javascript
347354
:emphasize-lines: 1
348355

source/reference/command/distinct.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,11 @@ Definition
3636

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

39+
.. include:: /includes/note-distinct-bson-limit-agg-alternative.rst
40+
3941
MongoDB also provides the shell wrapper method
4042
:method:`db.collection.distinct()` for the :dbcommand:`distinct`
41-
command. Additionally, many MongoDB :term:`drivers <driver>` also
43+
command. Additionally, many MongoDB :term:`drivers <driver>`
4244
provide a wrapper method. Refer to the specific driver documentation.
4345

4446
Behavior

source/reference/method/db.collection.distinct.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,9 @@ Definition
2222
.. include:: /includes/apiargs/method-db.collection.distinct-param.rst
2323

2424
The :method:`db.collection.distinct()` method provides a wrapper
25-
around the :dbcommand:`distinct` command. Results must not be larger
26-
than the maximum :ref:`BSON size <limit-bson-document-size>`.
25+
around the :dbcommand:`distinct` command.
26+
27+
.. include:: /includes/note-distinct-bson-limit-agg-alternative.rst
2728

2829
.. _distinct-method-options:
2930

0 commit comments

Comments
 (0)