|
64 | 64 | "import static com.mongodb.client.model.Aggregates.project;\n", |
65 | 65 | "import static com.mongodb.client.model.Aggregates.sort;\n", |
66 | 66 | "import static com.mongodb.client.model.Aggregates.addFields;\n", |
| 67 | + "import static com.mongodb.client.model.Aggregates.limit;\n", |
| 68 | + "\n", |
67 | 69 | "\n", |
68 | 70 | "import org.bson.Document;\n", |
69 | 71 | "import org.bson.conversions.Bson;\n", |
|
163 | 165 | "\n", |
164 | 166 | "AggregateIterable<Document> result = books.aggregate(\n", |
165 | 167 | " List.of(\n", |
166 | | - " Aggregates.match(Filters.in(\"genres\", \"Family Life\", \"Fiction\")),\n", |
| 168 | + " Aggregates.match(in(\"genres\", \"Family Life\", \"Fiction\")),\n", |
167 | 169 | " Aggregates.project(new Document()\n", |
168 | 170 | " .append(\"title\", 1)\n", |
169 | 171 | " .append(\"genres\", 1)\n", |
|
205 | 207 | }, |
206 | 208 | "outputs": [], |
207 | 209 | "source": [ |
208 | | - "// type your code here" |
| 210 | + "// TYPE YOUR CODE HERE\n", |
| 211 | + "\n", |
| 212 | + "AggregateIterable<Document> result = books.aggregate(\n", |
| 213 | + " List.of(\n", |
| 214 | + " <REPLACE_WITH_MATCH_STAGE>,\n", |
| 215 | + " <REPLACE_WITH_PROJECT_STAGE>\n", |
| 216 | + " )\n", |
| 217 | + ");\n", |
| 218 | + "\n", |
| 219 | + "// Iterate through the results\n", |
| 220 | + "for (Document doc : result) {\n", |
| 221 | + " System.out.println(\"book: \" + doc.toJson());\n", |
| 222 | + "}" |
209 | 223 | ] |
210 | 224 | }, |
211 | 225 | { |
|
228 | 242 | }, |
229 | 243 | "outputs": [], |
230 | 244 | "source": [ |
231 | | - "// type your code here" |
| 245 | + "// TYPE YOUR CODE HERE\n", |
| 246 | + "\n", |
| 247 | + "AggregateIterable<Document> result = books.aggregate(\n", |
| 248 | + " List.of(\n", |
| 249 | + " <REPLACE_WITH_MATCH_STAGE>,\n", |
| 250 | + " <REPLACE_WITH_ADDFIELDS_STAGE>\n", |
| 251 | + " )\n", |
| 252 | + ");\n", |
| 253 | + "\n", |
| 254 | + "// Iterate through the results\n", |
| 255 | + "for (Document doc : result) {\n", |
| 256 | + " System.out.println(\"book: \" + doc.toJson());\n", |
| 257 | + "}" |
232 | 258 | ] |
233 | 259 | } |
234 | 260 | ], |
|
0 commit comments