Skip to content

Commit e21df54

Browse files
authored
DOCSP-32718: multikey code comments (#768)
* DOCSP-32718: multikey code comments * fixes
1 parent fed1373 commit e21df54

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

source/code-snippets/indexes/multikey.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1+
// Create a multikey index
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

@@ -13,23 +14,27 @@ async function run() {
1314
const database = client.db("sample_mflix");
1415
const movies = database.collection("movies");
1516

16-
// Create a multikey index on the "cast" field
17+
// Create a multikey index on the "cast" field in the "movies" collection
1718
const result = await movies.createIndex({ cast: 1 });
1819
// end-idx
1920

21+
// Print the result of creating the index
2022
console.log(`Index created: ${result}`);
2123

2224
// begin-query
2325
const query = { cast: "Viola Davis" };
2426
const projection = { _id: 0, cast: 1 , title: 1 };
2527

28+
// Perform a find operation with the preceding filter and projection
2629
const cursor = movies
2730
.find(query)
2831
.project(projection);
2932
// end-query
3033

3134
} finally {
35+
// Close the connection after the operation completes
3236
await client.close();
3337
}
3438
}
39+
// Run the program and print any errors
3540
run().catch(console.dir);

0 commit comments

Comments
 (0)