|
92 | 92 | "outputs": [], |
93 | 93 | "source": [ |
94 | 94 | "Bson poetryBooks = eq(\"genres\", \"Poetry\");\n", |
95 | | - "FindIterable<Document> cursor = books.find(poetryBooks);\n", |
96 | | - "\n", |
97 | | - "if (cursor != null) {\n", |
98 | | - " for(Document b: cursor) {\n", |
99 | | - " System.out.println(\"Book: \" + b.toJson());\n", |
100 | | - " }\n", |
101 | | - "} else {\n", |
102 | | - " System.out.println(\"Empty collection\");\n", |
103 | | - "}" |
| 95 | + "books.find(poetryBooks)\n", |
| 96 | + " .forEach(b -> System.out.println(\"Book: \" + b.toJson()));" |
104 | 97 | ] |
105 | 98 | }, |
106 | 99 | { |
|
123 | 116 | "outputs": [], |
124 | 117 | "source": [ |
125 | 118 | "Bson familyLifeAndFictionBooks = all(\"genres\", \"Family Life\", \"Fiction\");\n", |
126 | | - "FindIterable<Document> cursor = books.find(familyLifeAndFictionBooks);\n", |
127 | 119 | "\n", |
128 | | - "if (cursor != null) {\n", |
129 | | - " for(Document b: cursor) {\n", |
130 | | - " System.out.println(\"Book: \" + b.toJson());\n", |
131 | | - " }\n", |
132 | | - "} else {\n", |
133 | | - " System.out.println(\"Empty collection\");\n", |
134 | | - "}" |
| 120 | + "books.find(familyLifeAndFictionBooks)\n", |
| 121 | + " .forEach(b -> System.out.println(\"Book: \" + b.toJson()));" |
135 | 122 | ] |
136 | 123 | }, |
137 | 124 | { |
|
154 | 141 | "outputs": [], |
155 | 142 | "source": [ |
156 | 143 | "Bson familyLifeOrFictionBooks = in(\"genres\", \"Family Life\", \"Fiction\");\n", |
157 | | - "FindIterable<Document> cursor = books.find(familyLifeOrFictionBooks);\n", |
158 | 144 | "\n", |
159 | | - "if (cursor != null) {\n", |
160 | | - " for(Document b: cursor) {\n", |
161 | | - " System.out.println(\"Book: \" + b.toJson());\n", |
162 | | - " }\n", |
163 | | - "} else {\n", |
164 | | - " System.out.println(\"Empty collection\");\n", |
165 | | - "}" |
| 145 | + "books.find(familyLifeOrFictionBooks)\n", |
| 146 | + " .forEach(b -> System.out.println(\"Book: \" + b.toJson()));" |
166 | 147 | ] |
167 | 148 | }, |
168 | 149 | { |
|
187 | 168 | "outputs": [], |
188 | 169 | "source": [ |
189 | 170 | "Bson poetryAndFictionBooks = eq(\"genres\", Arrays.asList(\"Poetry\", \"Fiction\"));\n", |
190 | | - "FindIterable<Document> cursor = books.find(poetryAndFictionBooks);\n", |
191 | 171 | "\n", |
192 | | - "if (cursor != null) {\n", |
193 | | - " for(Document b: cursor) {\n", |
194 | | - " System.out.println(\"Book: \" + b.toJson());\n", |
195 | | - " }\n", |
196 | | - "} else {\n", |
197 | | - " System.out.println(\"Empty collection\");\n", |
198 | | - "}" |
| 172 | + "books.find(poetryAndFictionBooks)\n", |
| 173 | + " .forEach(b -> System.out.println(\"Book: \" + b.toJson()));" |
199 | 174 | ] |
200 | 175 | } |
201 | 176 | ], |
|
0 commit comments