Skip to content

Commit fed1373

Browse files
authored
DOCSP-32718: listindexes code comments (#767)
1 parent 0171bc7 commit fed1373

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed
Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,33 @@
1+
// List indexes
2+
13
const { MongoClient } = require("mongodb");
24

3-
// Replace the following with your MongoDB deployment's connection
4-
// string.
5+
// Replace the placeholders with your credentials
56
const uri =
67
"mongodb+srv://<user>:<password>@<cluster-url>?writeConcern=majority";
78

89
const client = new MongoClient(uri);
910

10-
import { MongoClient } from "mongodb";
11+
// Access a collection from a database
1112
const database = client.db("<databaseName>");
1213
const collection = database.collection("<collectionName>");
1314

1415
async function run() {
1516
try {
1617
// start listIndexes example
18+
// List the indexes on the collection and output them as an array
1719
const result = await collection.listIndexes().toArray();
20+
21+
// Print the list of indexes
1822
console.log("Existing indexes:\n");
1923
for(const doc in result){
2024
console.log(doc);
2125
}
2226
// end listIndexes example
2327
} finally {
28+
// Close the connection after the operation completes
2429
await client.close();
2530
}
2631
}
32+
// Run the program and print any errors
2733
run().catch(console.dir);

0 commit comments

Comments
 (0)