-
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
Changes from 4 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,23 +19,28 @@ public class CurrentAPI { | |
|
||
public static void main(String[] args) throws InterruptedException { | ||
CurrentAPI c = new CurrentAPI(); | ||
|
||
c.example1(); | ||
c.example2(); | ||
|
||
} | ||
|
||
private void example1() { | ||
// 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); | ||
|
||
// Prints the first document retrieved from the collection as JSON | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Issue: Suggestion: |
||
Document doc = col.find().first(); | ||
System.out.println(doc.toJson()); | ||
// end current-api-example | ||
client.close(); | ||
} | ||
|
||
private void example2() { | ||
// Creates a MongoClient that requests write acknowledgement from at least one node | ||
// start current-api-mongoclientsettings-example | ||
MongoClientSettings options = MongoClientSettings.builder() | ||
.applyConnectionString(new ConnectionString(URI)) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -52,35 +52,41 @@ public static void main(String [] args){ | |
} | ||
|
||
private void deleteManyExample(){ | ||
// Deletes all documents in the collection that contain a "qty" value of 0 | ||
// 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 commentThe reason will be displayed to describe this comment to others. Learn more. Issue: Suggestion: |
||
System.out.println(collection.findOneAndDelete(filter).toJson()); | ||
// end findOneAndDeleteExample | ||
} | ||
|
||
private void findOneAndDeleteNullExample(){ | ||
// Deletes the first document with a "qty" value of 1 and prints the deleted document | ||
// begin findOneAndDeleteNullExample | ||
Bson filter = Filters.eq("qty", 1); | ||
System.out.println(collection.findOneAndDelete(filter)); | ||
// end findOneAndDeleteNullExample | ||
} | ||
|
||
private void deleteOneExample(){ | ||
// Deletes the first document with a "color" value of "yellow" | ||
// 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 commentThe reason will be displayed to describe this comment to others. Learn more. Suggestion: |
||
Bson filter = Filters.empty(); | ||
collection.find(filter).forEach(doc -> System.out.println(doc.toJson())); | ||
|
||
if (drop){ | ||
collection.drop(); | ||
} | ||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -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 commentThe reason will be displayed to describe this comment to others. Learn more. Issue: Suggestion:
Suggested change
|
||||||
MongoDatabase database = mongoClient.getDatabase("sample_mflix"); | ||||||
MongoCollection<Document> collection = database.getCollection("theaters"); | ||||||
|
||||||
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 commentThe reason will be displayed to describe this comment to others. Learn more. Issue: Suggestion:
Suggested change
|
||||||
Bson query = near("location.geo", centralPark, 10000.0, 5000.0); | ||||||
|
||||||
// Creates a projection to include only the "location.address.city" field in the results | ||||||
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 commentThe reason will be displayed to describe this comment to others. Learn more. Issue: Suggestion: |
||||||
collection.find(query) | ||||||
.projection(projection) | ||||||
.forEach(doc -> System.out.println(doc.toJson())); | ||||||
|
@@ -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 commentThe reason will be displayed to describe this comment to others. Learn more. Suggestion: |
||||||
// Creates a Polygon instance for a geolocation query | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Suggestion: E.g. |
||||||
Polygon longIslandTriangle = new Polygon(Arrays.asList(new Position(-72, 40), | ||||||
new Position(-74, 41), | ||||||
new Position(-72, 39), | ||||||
new Position(-72, 40))); | ||||||
|
||||||
// Creates a projection to include only the "location.address.city" field in the results | ||||||
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 commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
Bson geoWithinComparison = geoWithin("location.geo", longIslandTriangle); | ||||||
|
||||||
// Prints the projected field of the results from the geolocation query as JSON | ||||||
collection.find(geoWithinComparison) | ||||||
.projection(projection) | ||||||
.forEach(doc -> System.out.println(doc.toJson())); | ||||||
|
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.