|
1 |
| -========================================== |
2 |
| -Distinct Values of a Field in a Collection |
3 |
| -========================================== |
| 1 | +=============================== |
| 2 | +Find Distinct Values of a Field |
| 3 | +=============================== |
4 | 4 |
|
5 | 5 | .. default-domain:: mongodb
|
6 | 6 |
|
7 |
| -You can retrieve a list of distinct values for a field across a collection |
8 |
| -by using the `distinct() |
9 |
| -<https://mongodb.github.io/node-mongodb-native/3.4/api/Collection.html#distinct>`_ |
10 |
| -method. Call the ``distinct()`` method on a Collection object with |
11 |
| -a document field name parameter as a String to produce a list that contains |
12 |
| -one of each of the different values found in the specified document field. |
13 |
| - |
14 |
| -You can specify a document field within an *embedded document* using `dot |
15 |
| -notation |
16 |
| -<https://docs.mongodb.com/manual/core/document/#embedded-documents>`_. If |
17 |
| -you call ``distinct()`` on an document field that contains an array, each |
18 |
| -element of the array is treated as a separate value. |
19 |
| - |
20 |
| -You can provide an optional query document to narrow the set of documents that |
21 |
| -are searched and an optional Object to specify additional query parameters. |
22 |
| -For details on the optional parameters, see the |
23 |
| -`distinct() method in the API documentation |
24 |
| -<https://mongodb.github.io/node-mongodb-native/3.4/api/Collection.html#distinct>`_. |
| 7 | +You can retrieve a list of distinct values for a field across a |
| 8 | +collection by using the :node-docs:`distinct() |
| 9 | +<api/Collection.html#distinct>` method. Call the ``distinct()`` method |
| 10 | +on a Collection object with a document field name parameter as a String |
| 11 | +to produce a list that contains one of each of the different values |
| 12 | +found in the specified document field. |
| 13 | + |
| 14 | +You can specify a document field within an *embedded document* using |
| 15 | +:manual:`dot |
| 16 | +notation </core/document/#embedded-documents>`. If |
| 17 | +you call ``distinct()`` on an document field that contains an array, |
| 18 | +each element of the array is treated as a separate value. |
| 19 | + |
| 20 | +You can provide an optional query document to narrow the set of |
| 21 | +documents that are searched and an optional Object to specify additional |
| 22 | +query parameters. For details on the optional parameters, see the |
| 23 | +:node-docs:`distinct() method in the API documentation |
| 24 | +<api/Collection.html#distinct>`. |
25 | 25 |
|
26 | 26 | The ``distinct()`` method returns a
|
27 |
| -`Promise <https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise>`_ |
28 |
| -that resolves to an |
29 |
| -`Array <https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array>`_ |
30 |
| -that contains each of the different values. If none of the documents in the |
31 |
| -collection contain the field specified in the method call, it returns an |
32 |
| -empty Array. |
| 27 | +:mdn:`Promise </Web/JavaScript/Reference/Global_Objects/Promise>` that |
| 28 | +resolves to an :mdn:`Array |
| 29 | +</Web/JavaScript/Reference/Global_Objects/Array>` that contains each of |
| 30 | +the different values. If none of the documents in the collection contain |
| 31 | +the field specified in the method call, it returns an empty Array. |
33 | 32 |
|
34 | 33 | If you specify a value for the document field name that is not of type
|
35 |
| -String such as a Document, Array, Number, or ``null``, the method does not |
36 |
| -execute and returns a TypeMismatch error with a message that resembles |
37 |
| -the following: |
| 34 | +String such as a Document, Array, Number, or ``null``, the method does |
| 35 | +not execute and returns a TypeMismatch error with a message that |
| 36 | +resembles the following: |
38 | 37 |
|
39 | 38 | ::
|
40 | 39 |
|
|
0 commit comments