Skip to content

Commit 9d0698a

Browse files
committed
DOCSP-33345: Java comments pt. 9 (#478)
* DOCSP-33345: Java comments pt. 9 * edit * reword (cherry picked from commit 6c81d59)
1 parent c1a9bb6 commit 9d0698a

File tree

3 files changed

+18
-2
lines changed

3 files changed

+18
-2
lines changed

source/includes/fundamentals/code-snippets/Retrieve.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,15 +51,21 @@ public static void main(String [] args){
5151
}
5252

5353
private void findExample(){
54+
// Creates a filter to match documents that have a "qty" value between 3 and 9
5455
// begin findExample
5556
Bson filter = Filters.and(Filters.gt("qty", 3), Filters.lt("qty", 9));
57+
58+
// Retrieves documents that match the filter and prints them as JSON
5659
collection.find(filter).forEach(doc -> System.out.println(doc.toJson()));
5760
// end findExample
5861
}
5962

6063
private void aggregateExample(){
64+
// Creates an empty filter to match all documents in the collection
6165
// begin aggregateExample
6266
Bson filter = Filters.empty();
67+
68+
// Prints the collection's "color" values and each value's frequency in descending frequency order
6369
collection.aggregate(Arrays.asList(
6470
Aggregates.match(filter),
6571
Aggregates.group("$color", Accumulators.sum("qty", "$qty")),
@@ -69,13 +75,16 @@ private void aggregateExample(){
6975
}
7076

7177
private void watchExample(){
78+
// Creates instructions to match insert and update operations
7279
// begin watchExample
7380
List<Bson> pipeline = Arrays.asList(
7481
Aggregates.match(Filters.in("operationType", Arrays.asList("insert", "update"))));
7582

83+
// Creates a change stream that receives change events for the specified operations
7684
ChangeStreamIterable<Document> changeStream = database.watch(pipeline)
7785
.fullDocument(FullDocument.UPDATE_LOOKUP);
7886

87+
// Prints a message each time the change stream receives a change event
7988
changeStream.forEach(event ->
8089
System.out.println("Received a change to the collection: " + event));
8190
// end watchExample

source/includes/fundamentals/code-snippets/SearchText.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,27 +47,31 @@ public static void main(String [] args){
4747
}
4848

4949
private void termExample(){
50+
// Retrieves and prints documents containing the "fast" string in any fields associated with a text index
5051
// begin termExample
5152
Bson filter = Filters.text("fast");
5253
collection.find(filter).forEach(doc -> System.out.println(doc.toJson()));
5354
// end termExample
5455
}
5556

5657
private void multipleTermExample(){
58+
// Retrieves and prints documents containing the "fate 7" string in any fields associated with a text index
5759
// begin multipleTermExample
5860
Bson filter = Filters.text("fate 7");
5961
collection.find(filter).forEach(doc -> System.out.println(doc.toJson()));
6062
// end multipleTermExample
6163
}
6264

6365
private void negateExample(){
66+
// Retrieves and prints documents containing the "furious" but not the "fast" string in any fields associated with a text index
6467
// begin negateExample
6568
Bson filter = Filters.text("furious -fast");
6669
collection.find(filter).forEach(doc -> System.out.println(doc.toJson()));
6770
// end negateExample
6871
}
6972

7073
private void phraseExample(){
74+
// Retrieves and prints documents containing the "fate of the furious" string in any fields associated with a text index
7175
// begin phraseExample
7276
Bson filter = Filters.text("\"fate of the furious\"");
7377
collection.find(filter).forEach(doc -> System.out.println(doc.toJson()));

source/includes/fundamentals/code-snippets/Skip.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,12 @@ public static void main (String [] args){
3939
}
4040

4141
private void skipExample(){
42+
// Prints all remaining documents as JSON after applying a descending sort and omitting the first 5 documents
4243
// begin skipExample
4344
import com.mongodb.client.model.Filters;
4445
import com.mongodb.client.model.Sorts;
4546

46-
// <MongoCollection setup code here>
47+
// Add your MongoCollection setup code here
4748

4849
Bson filter = Filters.empty();
4950
collection.find(filter)
@@ -54,6 +55,7 @@ private void skipExample(){
5455
}
5556

5657
private void noResultsExample(){
58+
// Prints all remaining documents as JSON after applying a descending sort and omitting the first 9 documents
5759
// begin noResultsExample
5860
Bson filter = Filters.empty();
5961
collection.find(filter)
@@ -64,12 +66,13 @@ private void noResultsExample(){
6466
}
6567

6668
private void skipAggregateExample(){
69+
// Prints all remaining documents after using an aggregation pipeline to apply a sort and omit the first 5 documents
6770
// begin skipAggregateExample
6871
import com.mongodb.client.model.Filters;
6972
import com.mongodb.client.model.Sorts;
7073
import com.mongodb.client.model.Aggregates;
7174

72-
// <MongoCollection setup code here>
75+
// Add your MongoCollection setup code here
7376

7477
Bson filter = Filters.empty();
7578
collection.aggregate(Arrays.asList(

0 commit comments

Comments
 (0)