Skip to content

DOCSP-33345: Java comments pt. 4 #472

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 11 commits into from
Oct 27, 2023

Conversation

norareidy
Copy link
Contributor

@norareidy norareidy commented Oct 10, 2023

@norareidy norareidy force-pushed the DOCSP-33345-java-comments-4 branch from d81935b to ce57a6d Compare October 10, 2023 18:48
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.

Lots of great work here.

I think making the comments more consistent would be helpful in understanding the code, both by users and LLMs.

I think it might be helpful to keep track of (perhaps a separate doc) what code should be commented and which should not. I think we paired on some of this, but happy to contribute to a more formal list. I think it's a little unclear to us since we haven't gotten detailed feedback from CodeWhisperer, so maybe that list could help us identify the concerns.

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.

Looks good. There are a couple issues to address before merging, but approving since they're straightforward fixes.

collection.bulkWrite(bulkOperations);

// Prints a message if any exceptions occur during the operations
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Per the code comments sheet:

Suggested change
// Prints a message if any exceptions occur during the operations
// Prints a message if any exceptions occur during the bulk write operation

InsertOneModel<Document> insertDoc = new InsertOneModel<>(new Document("_id", 6)
.append("name", "Zaynab Omar")
.append("age", 37));

// Creates instructions to replace the matching document
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Per the code comments sheet:

Suggested change
// Creates instructions to replace the matching document
// Creates instructions to replace the first document that matches the query

UpdateOneModel<Document> updateDoc = new UpdateOneModel<>(Filters.eq("name", "Zaynab Omar"),
Updates.set("name", "Zaynab Hassan"));

// Creates instructions to delete all matching documents
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 it would be good for consistency to mention matching the query. Added to the code comment sheet.

Suggested change
// Creates instructions to delete all matching documents
// Creates instructions to delete all documents that match the query

.append("name", "Zaynab Omar")
.append("age", 37));

// Creates instructions to replace the matching document
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 it's important to mention the first document matched by the query for all instances of "OneModel"s as described on the code comments sheet as it is otherwise inaccurate for the case in which there are more than one matches:

Suggested change
// Creates instructions to replace the matching document
// Creates instructions to replace the matching document

Applies to all instances.

.collation(Collation.builder().locale("de").collationStrength(CollationStrength.PRIMARY).build());

// Prints the results of the aggregation that tallied value frequencies and sorted the results
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 it could be good to keep the description consistent (e.g. line 65) within the file:

Suggested change
// Prints the results of the aggregation that tallied value frequencies and sorted the results
// Prints the JSON representation of the results

Bson filter = Filters.eq("reserved", false);

// Atomically finds and updates a document to mark it as reserved
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 we landed on the following for findOneAndDelete which should be applied to findOneAndUpdate in the code comments sheet:

Suggested change
// Atomically finds and updates a document to mark it as reserved
// Updates the first document that matches the filter to mark it as reserved

Applies to https://github.com/mongodb/docs-java/pull/472/files#diff-3d6441156a561267d83bde841144e80a788371a97373d78a95825cb1d584c919R118

@@ -6,6 +6,9 @@
import com.mongodb.client.MongoDatabase;
import com.mongodb.client.model.*;
import com.mongodb.client.result.InsertOneResult;

import docs.builders.Filters;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question:
Is this import necessary? From a quick scan, I can't tell which file is in the docs.builders package. Please let me know if there's any reason not to delete it.

@@ -49,16 +56,26 @@ private void findOneAndUpdateExample() {
MongoCollection<Document> collection = getCollection();
//start findOneAndUpdate-example
// <MongoCollection set up code here>

// Creates a projection to exclude the "_id" field from the printed documents
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Issue:

I think printed documents is inaccurate. The projection tells the server which fields to return.

Suggestion:

I think it would be better to use the language "retrieved documents" similar to the descriptions of the projection method used in the code comments sheet:

Suggested change
// Creates a projection to exclude the "_id" field from the printed documents
// Creates a projection to exclude the "_id" field from the retrieved documents

@@ -67,18 +79,24 @@ private static void findOneAndUpdateExample(MongoCollection<Document> collection
.collation(Collation.builder().locale("de@collation=phonebook").build())
.sort(Sorts.ascending("first_name"))
.returnDocument(ReturnDocument.AFTER));

// Prints the JSON representation of the updated document, if an update occurred
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 it would be more grammatical to omit this comma.

Suggested change
// Prints the JSON representation of the updated document, if an update occurred
// Prints the JSON representation of the updated document if an update occurred

@norareidy norareidy merged commit 4b9070c into mongodb:master Oct 27, 2023
@norareidy norareidy deleted the DOCSP-33345-java-comments-4 branch October 27, 2023 17:31
norareidy added a commit that referenced this pull request Oct 27, 2023
* DOCSP-33345: Java code comments pt. 4

* bulkwrite CC feedback

* applying CC feedback

* small edit

* half of feedback

* rest of feedback

* single line comment

* duplicate comments sheet suggestions

* small edit

* final feedback

(cherry picked from commit 4b9070c)
norareidy added a commit that referenced this pull request Oct 27, 2023
* DOCSP-33345: Java code comments pt. 4

* bulkwrite CC feedback

* applying CC feedback

* small edit

* half of feedback

* rest of feedback

* single line comment

* duplicate comments sheet suggestions

* small edit

* final feedback

(cherry picked from commit 4b9070c)
norareidy added a commit that referenced this pull request Oct 27, 2023
* DOCSP-33345: Java code comments pt. 4

* bulkwrite CC feedback

* applying CC feedback

* small edit

* half of feedback

* rest of feedback

* single line comment

* duplicate comments sheet suggestions

* small edit

* final feedback

(cherry picked from commit 4b9070c)
(cherry picked from commit fd983e9)
norareidy added a commit that referenced this pull request Oct 27, 2023
* DOCSP-33345: Java code comments pt. 4

* bulkwrite CC feedback

* applying CC feedback

* small edit

* half of feedback

* rest of feedback

* single line comment

* duplicate comments sheet suggestions

* small edit

* final feedback

(cherry picked from commit 4b9070c)
(cherry picked from commit fd983e9)
norareidy added a commit that referenced this pull request Oct 27, 2023
* DOCSP-33345: Java code comments pt. 4

* bulkwrite CC feedback

* applying CC feedback

* small edit

* half of feedback

* rest of feedback

* single line comment

* duplicate comments sheet suggestions

* small edit

* final feedback

(cherry picked from commit 4b9070c)
(cherry picked from commit fd983e9)
norareidy added a commit that referenced this pull request Oct 27, 2023
* DOCSP-33345: Java code comments pt. 4

* bulkwrite CC feedback

* applying CC feedback

* small edit

* half of feedback

* rest of feedback

* single line comment

* duplicate comments sheet suggestions

* small edit

* final feedback

(cherry picked from commit 4b9070c)
(cherry picked from commit fd983e9)
norareidy added a commit that referenced this pull request Oct 27, 2023
* DOCSP-33345: Java code comments pt. 4

* bulkwrite CC feedback

* applying CC feedback

* small edit

* half of feedback

* rest of feedback

* single line comment

* duplicate comments sheet suggestions

* small edit

* final feedback

(cherry picked from commit 4b9070c)
(cherry picked from commit fd983e9)
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