Skip to content

Commit 482ef66

Browse files
authored
DOCSP-32718: count UE code comments (#755)
* DOCSP-32718: count UE code comments * CC comments
1 parent 85be2f0 commit 482ef66

File tree

1 file changed

+9
-8
lines changed
  • source/code-snippets/usage-examples

1 file changed

+9
-8
lines changed
Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
// Count documents in a collection
2+
13
import { MongoClient } from "mongodb";
24

3-
// Replace the uri string with your MongoDB deployment's connection string.
5+
// Replace the uri string with your MongoDB deployment's connection string
46
const uri = "<connection string uri>";
57

68
const client = new MongoClient(uri);
@@ -10,21 +12,20 @@ async function run() {
1012
const database = client.db("sample_mflix");
1113
const movies = database.collection("movies");
1214

13-
// Estimate the total number of documents in the collection
14-
// and print out the count.
15+
/* Print the estimate of the number of documents in the
16+
"movies" collection */
1517
const estimate = await movies.estimatedDocumentCount();
1618
console.log(`Estimated number of documents in the movies collection: ${estimate}`);
1719

18-
// Query for movies from Canada.
20+
/* Print the number of documents in the "movies" collection that
21+
match the specified query */
1922
const query = { countries: "Canada" };
20-
21-
// Find the number of documents that match the specified
22-
// query, (i.e. with "Canada" as a value in the "countries" field)
23-
// and print out the count.
2423
const countCanada = await movies.countDocuments(query);
2524
console.log(`Number of movies from Canada: ${countCanada}`);
2625
} finally {
26+
// Close the connection after the operations complete
2727
await client.close();
2828
}
2929
}
30+
// Run the program and print any thrown exceptions
3031
run().catch(console.dir);

0 commit comments

Comments
 (0)