-
Notifications
You must be signed in to change notification settings - Fork 43
DOCSP-33345: Java comments pt. 5 #473
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
DOCSP-33345: Java comments pt. 5 #473
Conversation
c.example1(); | ||
c.example2(); | ||
|
||
} | ||
|
||
private void example1() { | ||
// Connect to a MongoDB instance with the current API |
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.
Issue:
Use the indicative mood (verb form that makes a statement). See https://docs.google.com/document/d/1Bnhh1OsGRUuXo_6yVUASGWiSX6sWuqrEFxPP6sLZDHM/edit for examples.
Also, I think "by using" is suitable and more compliant with the style guide.
Suggestion:
Maybe something like the following would be accurate and follow the style guide:
"Connects to MongoDB and retrieves a document by using the non-legacy API"
// start current-api-example | ||
MongoClient client = MongoClients.create(URI); | ||
MongoDatabase db = client.getDatabase(DATABASE); | ||
MongoCollection<Document> col = db.getCollection(COLLECTION); | ||
|
||
// Find and print a document in your collection to test your connection |
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.
Issue:
Use the indicative mood (verb form that makes a statement).
Suggestion:
I think it's not necessary to mention the "test your connection" part since it doesn't explicitly run any tests. All operations would implicitly test the connection given that they would throw a runtime exception if unable to connect, similar to this operation.
I think the following might be an accurate summary comment that uses the indicative mood:
"Prints the first document retrieved from the collection in JSON format."
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.
Looks pretty good -- I appreciate that you referenced the code in which each snippet was included and provided the staging links for each page.
I think the feedback I provided is mostly repeat advice, but wanted to make sure I provided solutions.
c.example1(); | ||
c.example2(); | ||
|
||
} | ||
|
||
private void example1() { | ||
// Connects to a MongoDB instance with the current API |
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.
Issue:
From this comment, I think "by using" is suitable and more compliant with the style guide.
Suggestion:
I think the same suggestion as proposed in the linked comment applies.
// start current-api-example | ||
MongoClient client = MongoClients.create(URI); | ||
MongoDatabase db = client.getDatabase(DATABASE); | ||
MongoCollection<Document> col = db.getCollection(COLLECTION); | ||
|
||
// Finds and prints a document in your 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:
From this comment, I think there's a more accurate and concise way to describe the code.
collection.find(query) | ||
.projection(projection) | ||
.forEach(doc -> System.out.println(doc.toJson())); | ||
// end findExample | ||
} | ||
|
||
private void rangeExample() { | ||
// Accesses the "theaters" collection in the "sample_mflix" database | ||
MongoDatabase database = mongoClient.getDatabase("sample_mflix"); | ||
MongoCollection<Document> collection = database.getCollection("theaters"); | ||
// begin rangeExample | ||
|
||
// code to set up your mongo 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:
While this is not your code comment, could it be updated to either be consistent with other instances ("// ") or be replaced by a new imperative comment such as "// Add your MongoCollection setup code here"
Applies to all instances.
Document doc = col.find().first(); | ||
System.out.println(doc.toJson()); | ||
// end current-api-example | ||
client.close(); | ||
} | ||
|
||
private void example2() { | ||
// Sets a write concern on your client with the current API |
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 "sets a write concern" describes only a part of what the code snippet accomplishes. I also think there's always a write concern setting (whether a number or "majority"), so it would be more helpful to explain which one.
// Sets a write concern on your client with the current API | |
// Creates a MongoClient that requests write acknowledgement from at least one node. |
@@ -59,27 +60,31 @@ public static void main(String [] args){ | |||
} | |||
|
|||
private void forEachIteration(){ | |||
// Iterates through your cursor results |
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 to this comment, I think this should focus on the functionality instead of the code itself (which most of your comments achieve successfully).
// Iterates through your cursor results | |
// Prints all the documents in the collection in JSON format |
or
// Iterates through your cursor results | |
// Prints all the document in the collection as JSON |
Bson geoWithinComparison = geoWithin("coordinates", square); | ||
collection.find(geoWithinComparison).forEach(doc -> System.out.println(doc.toJson())); | ||
// end geoWithinComparison | ||
} | ||
|
||
private void preview(){ | ||
// Uses an empty filter to print all documents in the 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:
I think this should be omitted since it's setup code meant only for tech writers
@@ -144,6 +157,8 @@ private void preview(){ | |||
private void setupPaintCollection() { | |||
|
|||
List<Document> filterdata = new ArrayList<>(); | |||
|
|||
// Set up the "vendor" field for your documents |
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 should be omitted since it's setup code meant only for tech writers
@@ -153,6 +168,7 @@ private void setupPaintCollection() { | |||
String [] p7a = {"B", "C"}; | |||
String [] p8a = {"A", "D"}; | |||
|
|||
// Creates a series of documents and inserts them into the "paint" 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:
I think this should be omitted since it's setup code meant only for tech writers
@@ -178,6 +194,7 @@ private void setupPaintCollection() { | |||
private void setupBinaryCollection(){ | |||
List<Document> filterdata = new ArrayList<>(); | |||
|
|||
// Creates a series of documents and inserts them into the "binary" 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:
I think this should be omitted since it's setup code meant only for tech writers
@@ -194,6 +211,7 @@ private void setupPointsCollection(){ | |||
|
|||
List<Document> filterdata = new ArrayList<>(); | |||
|
|||
// Creates a series of documents and inserts them into the "points" 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:
I think this should be omitted since it's setup code meant only for tech writers
220a552
to
37d6011
Compare
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.
Looks good. Identified a few issues and suggestions to address before merging.
c.example1(); | ||
c.example2(); | ||
|
||
} | ||
|
||
private void example1() { | ||
// Connects to MongoDB and retrieves a document by using the non-legacy API |
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 "non-legacy API" could be confusing since it's not a common way to describe an API. I think it would only be used sparingly in which it was directly adjacent to the legacy API and that extra emphasis needed to be placed on the contrast.
// Connects to MongoDB and retrieves a document by using the non-legacy API | |
// Connects to MongoDB and retrieves a document |
// start current-api-example | ||
MongoClient client = MongoClients.create(URI); | ||
MongoDatabase db = client.getDatabase(DATABASE); | ||
MongoCollection<Document> col = db.getCollection(COLLECTION); | ||
|
||
// Prints the first document retrieved from the collection as JSON |
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.
Issue:
I think it could be good to only feature one Summary-type comment per method.
Suggestion:
I think omitting the Summary-type comment on line 29 ("Connects to MongoDB and retrieves a document...") would work well.
// begin deleteManyExample | ||
Bson filter = Filters.eq("qty", 0); | ||
collection.deleteMany(filter); | ||
// end deleteManyExample | ||
} | ||
|
||
private void findOneAndDeleteExample(){ | ||
// Deletes the first document with a "color" value of "purple" and prints the deleted document | ||
// begin findOneAndDeleteExample | ||
Bson filter = Filters.eq("color", purple); |
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.
Issue:
Io think this code won't compile because "purple" isn't a defined symbol.
Suggestion:
While it's not a code comment, I think it would be good to correct this to the string "purple".
// begin deleteOneExample | ||
Bson filter = Filters.eq("color", "yellow"); | ||
collection.deleteOne(filter); | ||
// end deleteOneExample | ||
} | ||
private void preview(boolean drop){ | ||
// Prints the results of a find operation as JSON |
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 it could be good to keep this consistent with other comments on similar code.
@@ -46,12 +46,19 @@ public void go() { | |||
private void nearExample() { | |||
// begin findExample | |||
|
|||
// code to set up your mongo client ... | |||
// Add your MongoCollection setup code here |
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.
Issue:
As the prior version of this comment mentions, this should be the "MongoClient" and not "MongoCollection".
Suggestion:
// Add your MongoCollection setup code here | |
// Add your MongoClient setup code here |
Point centralPark = new Point(new Position(-73.9667, 40.78)); | ||
|
||
// Creates a query that matches all theaters between 5,000 and 10,000 meters from the specified Point |
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.
Issue:
By itself, this query does not match theaters. Instead, it just matches all points within a range from the starting coordinates.
Suggestion:
// Creates a query that matches all theaters between 5,000 and 10,000 meters from the specified Point | |
// Creates a query that matches all locations between 5,000 and 10,000 meters from the specified Point |
@@ -63,13 +70,20 @@ private void rangeExample() { | |||
MongoCollection<Document> collection = database.getCollection("theaters"); | |||
// begin rangeExample | |||
|
|||
// code to set up your mongo collection ... | |||
// Add your MongoCollection setup code here |
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 it would be good to include a linebreak between two separate comments so it can be read and understood as a separate comment. I think the blank line after the Marker comment ("begin rangeExample") is not necessary.
@@ -63,13 +70,20 @@ private void rangeExample() { | |||
MongoCollection<Document> collection = database.getCollection("theaters"); | |||
// begin rangeExample | |||
|
|||
// code to set up your mongo collection ... | |||
// Add your MongoCollection setup code here | |||
// Creates a Polygon instance for a geolocation query |
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 it would be better to omit the part of this comment that just describes the code ("Polygon instance").
E.g.
"Creates a set of points that defines the bounds of a geospatial shape"
Bson projection = fields(include("location.address.city"), excludeId()); | ||
|
||
// Prints the projected field of the results from the geolocation query as JSON |
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.
Issue:
I think the correct term is geospatial query as described by the Server docs.
Suggestion:
I think it would be good to use the correct terminology in all instances.
Bson projection = fields(include("location.address.city"), excludeId()); | ||
|
||
// Creates a query that matches documents containing "location.geo" values within the specified Polygon |
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.
// Creates a query that matches documents containing "location.geo" values within the specified Polygon | |
// Creates a query that matches documents containing "location.geo" values within the specified shape |
* DOCSP-33345: Java comments pt. 5 * indicative mood * review feedback * sheet syntax * final feedback (cherry picked from commit e14a975)
* DOCSP-33345: Java comments pt. 5 * indicative mood * review feedback * sheet syntax * final feedback (cherry picked from commit e14a975)
* DOCSP-33345: Java comments pt. 5 * indicative mood * review feedback * sheet syntax * final feedback (cherry picked from commit e14a975)
* DOCSP-33345: Java comments pt. 5 * indicative mood * review feedback * sheet syntax * final feedback (cherry picked from commit e14a975)
* DOCSP-33345: Java comments pt. 5 * indicative mood * review feedback * sheet syntax * final feedback (cherry picked from commit e14a975)
* DOCSP-33345: Java comments pt. 5 * indicative mood * review feedback * sheet syntax * final feedback (cherry picked from commit e14a975)
* DOCSP-33345: Java comments pt. 5 * indicative mood * review feedback * sheet syntax * final feedback (cherry picked from commit e14a975)
Pull Request Info
PR Reviewing Guidelines
JIRA - https://jira.mongodb.org/browse/DOCSP-33345
Staging:
CurrentAPI - https://preview-mongodbnorareidy.gatsbyjs.io/java/DOCSP-33345-java-comments-5/faq/
Cursor - https://preview-mongodbnorareidy.gatsbyjs.io/java/DOCSP-33345-java-comments-5/fundamentals/crud/read-operations/cursor/
Delete - https://preview-mongodbnorareidy.gatsbyjs.io/java/DOCSP-33345-java-comments-5/fundamentals/crud/write-operations/delete/
Filters - https://preview-mongodbnorareidy.gatsbyjs.io/java/DOCSP-33345-java-comments-5/fundamentals/builders/filters/
Geo - https://preview-mongodbnorareidy.gatsbyjs.io/java/DOCSP-33345-java-comments-5/fundamentals/crud/read-operations/geo/
Self-Review Checklist