-
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
Conversation
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.
LGTM, a few suggestions.
@@ -1,12 +1,18 @@ | |||
/* Count documents in a collection*/ |
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.
@@ -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 comment
The reason will be displayed to describe this comment to others. Learn more.
Suggestion:
Open to discussion, but I think the code is self-describing and doesn't need a comment.
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 comment
The reason will be displayed to describe this comment to others. Learn more.
Suggestion:
Since this doesn't perform the connection, I would omit this comment. I think it describes itself well enough that a comment isn't necessary.
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 comment
The reason will be displayed to describe this comment to others. Learn more.
Suggestion:
Remove this and describe the access in a later comment when it is used. Similar comment as #754 (comment)
@@ -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 comment
The reason will be displayed to describe this comment to others. Learn more.
Suggestion:
Since this only creates an object that represents a query, I would omit this comment. If I'm interpreting this correctly, this is a narrative comment that might refer to a larger block of commands. However, when those blocks contain comments that apply just to the line or lines immediately afterwards, it's difficult to discern what the comments apply to.
// 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 comment
The reason will be displayed to describe this comment to others. Learn more.
Suggestion:
I think for multi-line comments, it would be good to use block-style comments "/* */"
I think this could be simplified to:
"Print the number of documents that match the query."
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 comment
The reason will be displayed to describe this comment to others. Learn more.
Suggestion:
Similar comment as #754 (comment)
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 comment
The 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..."
* DOCSP-32718: count UE code comments * CC comments
* DOCSP-32718: count UE code comments * CC comments
Pull Request Info
PR Reviewing Guidelines
JIRA - https://jira.mongodb.org/browse/DOCSP-32718
Staging - https://docs-mongodbcom-staging.corp.mongodb.com/drivers/docsworker-xlarge/NNNNN/
https://preview-mongodbrustagir.gatsbyjs.io/node/DOCSP-32718-count-comments/usage-examples/count/