Skip to content

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

Merged
merged 2 commits into from
Aug 31, 2023

Conversation

Copy link
Contributor

@ccho-mongodb ccho-mongodb left a 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*/
Copy link
Contributor

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.
Copy link
Contributor

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.
Copy link
Contributor

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.
Copy link
Contributor

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".
Copy link
Contributor

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.

Comment on lines 27 to 28
// 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.
Copy link
Contributor

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.
Copy link
Contributor

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.
Copy link
Contributor

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..."

@rustagir rustagir merged commit 482ef66 into mongodb:master Aug 31, 2023
rustagir added a commit that referenced this pull request Sep 7, 2023
* DOCSP-32718: count UE code comments

* CC comments
mongoKart pushed a commit to mongoKart/docs-node that referenced this pull request Nov 3, 2023
* DOCSP-32718: count UE code comments

* CC comments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants