@@ -50,36 +50,51 @@ public static void main(String [] args){
50
50
}
51
51
52
52
private void comparisonFilter (){
53
+ // Creates a filter to match documents that have a "qty" value over 7
53
54
// begin comparisonFilter
54
55
Bson filter = Filters .gt ("qty" , 7 );
56
+
57
+ // Retrieves documents that match the filter and prints them as JSON
55
58
collection .find (filter ).forEach (doc -> System .out .println (doc .toJson ()));
56
59
// end comparisonFilter
57
60
}
58
61
59
62
private void logicalFilter (){
63
+ // Creates a filter to match documents that have a "qty" value less than or equal to 7 and a "color" value of "pink"
60
64
// begin logicalFilter
61
65
Bson filter = Filters .and (Filters .lte ("qty" , 5 ), Filters .ne ("color" , "pink" ));
66
+
67
+ // Retrieves documents that match the filter and prints them as JSON
62
68
collection .find (filter ).forEach (doc -> System .out .println (doc .toJson ()));
63
69
// end logicalFilter
64
70
}
65
71
66
72
private void elementFilter (){
73
+ // Creates a filter to match documents that contain the "rating" field
67
74
// begin elementFilter
68
75
Bson filter = Filters .exists ("rating" );
76
+
77
+ // Retrieves documents that match the filter and prints them as JSON
69
78
collection .find (filter ).forEach (doc -> System .out .println (doc .toJson ()));
70
79
// end elementFilter
71
80
}
72
81
73
82
private void evaluationFilter (){
83
+ // Creates a filter to match documents that have a "color" value ending with the letter "k"
74
84
// begin evaluationFilter
75
85
Bson filter = Filters .regex ("color" , "k$" );
86
+
87
+ // Retrieves documents that match the filter and prints them as JSON
76
88
collection .find (filter ).forEach (doc -> System .out .println (doc .toJson ()));
77
89
// end evaluationFilter
78
90
}
79
91
80
92
private void arrayFilter (){
93
+ // Creates a filter to match documents whose "vendor" values are an array of 3 elements
81
94
// begin arrayFilter
82
95
Bson filter = Filters .size ("vendor" , 3 );
96
+
97
+ // Retrieves documents that match the filter and prints them as JSON
83
98
collection .find (filter ).forEach (doc -> System .out .println (doc .toJson ()));
84
99
// end arrayFilter
85
100
}
0 commit comments