File tree Expand file tree Collapse file tree 2 files changed +33
-0
lines changed Expand file tree Collapse file tree 2 files changed +33
-0
lines changed Original file line number Diff line number Diff line change
1
+ const { MongoClient } = require ( "mongodb" ) ;
2
+
3
+ // Replace the following with your MongoDB deployment's connection
4
+ // string.
5
+ const uri =
6
+ "mongodb+srv://<user>:<password>@<cluster-url>?writeConcern=majority" ;
7
+
8
+ const client = new MongoClient ( uri ) ;
9
+
10
+ async function run ( ) {
11
+ try {
12
+ const database = client . db ( "<database>" ) ;
13
+ const collection = database . collection ( "<collection>" ) ;
14
+ // start-listIndexes-example
15
+ const result = await collection . listIndexes ( ) . toArray ( ) ;
16
+ console . log ( "Existing indexes:\n" ) ;
17
+ for ( const doc in result ) {
18
+ console . log ( doc ) ;
19
+ }
20
+ // end-listIndexes-example
21
+ }
22
+ finally {
23
+ await client . close ( ) ;
24
+ }
25
+ }
26
+
27
+
Original file line number Diff line number Diff line change @@ -271,3 +271,9 @@ the following:
271
271
272
272
Refer to the :manual:`Unique Indexes page </core/index-unique>` in the
273
273
MongoDB server manual for more information.
274
+
275
+ .. literalinclude:: /code-snippets/indexes/listIndexes.js
276
+ :language: js
277
+ :start-after: start-listIndexes-example
278
+ :end-before: end-listIndexes-example
279
+ :dedent:
You can’t perform that action at this time.
0 commit comments