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
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions source/code-snippets/usage-examples/count.js
Original file line number Diff line number Diff line change
@@ -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.


// 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)

const database = client.db("sample_mflix");
const movies = database.collection("movies");

Expand All @@ -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.

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

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

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)

run().catch(console.dir);