File tree Expand file tree Collapse file tree 2 files changed +54
-3
lines changed
code-snippets/usage-examples Expand file tree Collapse file tree 2 files changed +54
-3
lines changed Original file line number Diff line number Diff line change
1
+ import { MongoClient } from "mongodb" ;
2
+
3
+ // Replace the uri string with your MongoDB deployment's connection string.
4
+ const uri =
5
+ "mongodb+srv://<user>:<password>@<cluster-url>?writeConcern=majority" ;
6
+
7
+ const client = new MongoClient ( uri ) ;
8
+
9
+ interface Movies {
10
+ directors : string ;
11
+ year : number ;
12
+ }
13
+
14
+ async function run ( ) {
15
+ try {
16
+ await client . connect ( ) ;
17
+
18
+ // define a database and collection on which to run the method
19
+ const database = client . db ( "sample_mflix" ) ;
20
+ const movies = database . collection < Movies > ( "movies" ) ;
21
+
22
+ const distinctValues = await movies . distinct ( "year" , {
23
+ directors : "Barbra Streisand" ,
24
+ } ) ;
25
+
26
+ console . log ( distinctValues ) ;
27
+ } finally {
28
+ await client . close ( ) ;
29
+ }
30
+ }
31
+ run ( ) . catch ( console . dir ) ;
Original file line number Diff line number Diff line change @@ -57,6 +57,26 @@ match movies that include "Barbara Streisand" as a ``director``.
57
57
58
58
.. include:: /includes/connect-guide-note.rst
59
59
60
- .. literalinclude:: /code-snippets/usage-examples/distinct.js
61
- :language: javascript
62
- :linenos:
60
+ .. tabs::
61
+
62
+ .. tab:: JavaScript
63
+ :tabid: javascript
64
+
65
+ .. literalinclude:: /code-snippets/usage-examples/distinct.js
66
+ :language: javascript
67
+ :linenos:
68
+
69
+ .. tab:: TypeScript
70
+ :tabid: typescript
71
+
72
+ .. literalinclude:: /code-snippets/usage-examples/distinct.ts
73
+ :language: typescript
74
+ :linenos:
75
+
76
+ If you run the example above, you should see output that resembles the following:
77
+
78
+ .. code-block:: json
79
+ :copyable: false
80
+
81
+ [ 1983, 1991, 1996 ]
82
+
You can’t perform that action at this time.
0 commit comments