-
Notifications
You must be signed in to change notification settings - Fork 52
DOCSP-32718: count UE code comments #755
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,18 @@ | ||
/* Count documents in a collection*/ | ||
|
||
// Import the MongoClient type from the mongodb package. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Suggestion: |
||
import { MongoClient } from "mongodb"; | ||
|
||
// Replace the uri string with your MongoDB deployment's connection string. | ||
const uri = "<connection string uri>"; | ||
|
||
// Create a new client and connect to MongoDB. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Suggestion: |
||
const client = new MongoClient(uri); | ||
|
||
async function run() { | ||
try { | ||
|
||
// Access the movies collection from the sample_mflix database. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Suggestion: |
||
const database = client.db("sample_mflix"); | ||
const movies = database.collection("movies"); | ||
|
||
|
@@ -15,16 +21,17 @@ async function run() { | |
const estimate = await movies.estimatedDocumentCount(); | ||
console.log(`Estimated number of documents in the movies collection: ${estimate}`); | ||
|
||
// Query for movies from Canada. | ||
// Query for movies where the countries field includes "Canada". | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Suggestion: |
||
const query = { countries: "Canada" }; | ||
|
||
// Find the number of documents that match the specified | ||
// query, (i.e. with "Canada" as a value in the "countries" field) | ||
// and print out the count. | ||
// query and print out the count. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Suggestion: I think this could be simplified to: |
||
const countCanada = await movies.countDocuments(query); | ||
console.log(`Number of movies from Canada: ${countCanada}`); | ||
} finally { | ||
// Close the client after the operations complete. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Suggestion: I think this doesn't close the client/MongoClient instance, but rather the connection. "Close the connection..." |
||
await client.close(); | ||
} | ||
} | ||
// Run the program and handle any errors that occur during execution. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Suggestion: |
||
run().catch(console.dir); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggestion:
For single-line comments, prefer "//". Also, when using multi-line comments, make sure the "*" does not connect with any word characters for readability.