@@ -50,36 +50,51 @@ public static void main(String [] args){
5050 }
5151
5252 private void comparisonFilter (){
53+ // Creates a filter to match documents that have a "qty" value over 7
5354 // begin comparisonFilter
5455 Bson filter = Filters .gt ("qty" , 7 );
56+
57+ // Retrieves documents that match the filter and prints them as JSON
5558 collection .find (filter ).forEach (doc -> System .out .println (doc .toJson ()));
5659 // end comparisonFilter
5760 }
5861
5962 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"
6064 // begin logicalFilter
6165 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
6268 collection .find (filter ).forEach (doc -> System .out .println (doc .toJson ()));
6369 // end logicalFilter
6470 }
6571
6672 private void elementFilter (){
73+ // Creates a filter to match documents that contain the "rating" field
6774 // begin elementFilter
6875 Bson filter = Filters .exists ("rating" );
76+
77+ // Retrieves documents that match the filter and prints them as JSON
6978 collection .find (filter ).forEach (doc -> System .out .println (doc .toJson ()));
7079 // end elementFilter
7180 }
7281
7382 private void evaluationFilter (){
83+ // Creates a filter to match documents that have a "color" value ending with the letter "k"
7484 // begin evaluationFilter
7585 Bson filter = Filters .regex ("color" , "k$" );
86+
87+ // Retrieves documents that match the filter and prints them as JSON
7688 collection .find (filter ).forEach (doc -> System .out .println (doc .toJson ()));
7789 // end evaluationFilter
7890 }
7991
8092 private void arrayFilter (){
93+ // Creates a filter to match documents whose "vendor" values are an array of 3 elements
8194 // begin arrayFilter
8295 Bson filter = Filters .size ("vendor" , 3 );
96+
97+ // Retrieves documents that match the filter and prints them as JSON
8398 collection .find (filter ).forEach (doc -> System .out .println (doc .toJson ()));
8499 // end arrayFilter
85100 }
0 commit comments