diff --git a/java/10_find.ipynb b/java/10_find.ipynb index ad4eae0..ac6d8d6 100644 --- a/java/10_find.ipynb +++ b/java/10_find.ipynb @@ -169,15 +169,9 @@ "outputs": [], "source": [ "Bson booksAfter2008 = gt(\"year\", 2008);\n", - "FindIterable cursor = books.find(booksAfter2008);\n", "\n", - "if (cursor != null) {\n", - " for(Document b: cursor) {\n", - " System.out.println(\"Book: \" + b.toJson());\n", - " }\n", - "} else {\n", - " System.out.println(\"Empty collection\");\n", - "}" + "books.find(booksAfter2008)\n", + " .forEach(b -> System.out.println(\"Book: \" + b.toJson())); " ] }, { @@ -202,15 +196,9 @@ "Bson booksWithLessThan50pages = lt(\"pages\", 50);\n", "Bson showOnlyTitleAndPages = Projections.fields(Projections.include(\"title\", \"pages\"));\n", "\n", - "FindIterable cursor = books.find(booksWithLessThan50pages).projection(showOnlyTitleAndPages);\n", - "\n", - "if (cursor != null) {\n", - " for(Document b: cursor) {\n", - " System.out.println(\"Book: \" + b.toJson());\n", - " }\n", - "} else {\n", - " System.out.println(\"Empty collection\");\n", - "}" + "books.find(booksWithLessThan50pages)\n", + " .projection(showOnlyTitleAndPages)\n", + " .forEach(b -> System.out.println(\"Book: \" + b.toJson()));" ] }, { @@ -238,15 +226,9 @@ " Projections.excludeId()\n", ");\n", "\n", - "FindIterable cursor = books.find(booksWithLessThan50pages).projection(showOnlyTitleAndPagesNoId);\n", - "\n", - "if (cursor != null) {\n", - " for(Document b: cursor) {\n", - " System.out.println(\"Book: \" + b.toJson());\n", - " }\n", - "} else {\n", - " System.out.println(\"Empty collection\");\n", - "}" + "books.find(booksWithLessThan50pages)\n", + " .projection(showOnlyTitleAndPagesNoId)\n", + " .forEach(b -> System.out.println(\"Book: \" + b.toJson())); " ] }, { diff --git a/java/11_find_arrays.ipynb b/java/11_find_arrays.ipynb index 08a72ae..8fc2db6 100644 --- a/java/11_find_arrays.ipynb +++ b/java/11_find_arrays.ipynb @@ -92,15 +92,8 @@ "outputs": [], "source": [ "Bson poetryBooks = eq(\"genres\", \"Poetry\");\n", - "FindIterable cursor = books.find(poetryBooks);\n", - "\n", - "if (cursor != null) {\n", - " for(Document b: cursor) {\n", - " System.out.println(\"Book: \" + b.toJson());\n", - " }\n", - "} else {\n", - " System.out.println(\"Empty collection\");\n", - "}" + "books.find(poetryBooks)\n", + " .forEach(b -> System.out.println(\"Book: \" + b.toJson()));" ] }, { @@ -123,15 +116,9 @@ "outputs": [], "source": [ "Bson familyLifeAndFictionBooks = all(\"genres\", \"Family Life\", \"Fiction\");\n", - "FindIterable cursor = books.find(familyLifeAndFictionBooks);\n", "\n", - "if (cursor != null) {\n", - " for(Document b: cursor) {\n", - " System.out.println(\"Book: \" + b.toJson());\n", - " }\n", - "} else {\n", - " System.out.println(\"Empty collection\");\n", - "}" + "books.find(familyLifeAndFictionBooks)\n", + " .forEach(b -> System.out.println(\"Book: \" + b.toJson()));" ] }, { @@ -154,15 +141,9 @@ "outputs": [], "source": [ "Bson familyLifeOrFictionBooks = in(\"genres\", \"Family Life\", \"Fiction\");\n", - "FindIterable cursor = books.find(familyLifeOrFictionBooks);\n", "\n", - "if (cursor != null) {\n", - " for(Document b: cursor) {\n", - " System.out.println(\"Book: \" + b.toJson());\n", - " }\n", - "} else {\n", - " System.out.println(\"Empty collection\");\n", - "}" + "books.find(familyLifeOrFictionBooks)\n", + " .forEach(b -> System.out.println(\"Book: \" + b.toJson()));" ] }, { @@ -187,15 +168,9 @@ "outputs": [], "source": [ "Bson poetryAndFictionBooks = eq(\"genres\", Arrays.asList(\"Poetry\", \"Fiction\"));\n", - "FindIterable cursor = books.find(poetryAndFictionBooks);\n", "\n", - "if (cursor != null) {\n", - " for(Document b: cursor) {\n", - " System.out.println(\"Book: \" + b.toJson());\n", - " }\n", - "} else {\n", - " System.out.println(\"Empty collection\");\n", - "}" + "books.find(poetryAndFictionBooks)\n", + " .forEach(b -> System.out.println(\"Book: \" + b.toJson()));" ] } ], diff --git a/java/30_insert.ipynb b/java/30_insert.ipynb index 182a284..c808e77 100644 --- a/java/30_insert.ipynb +++ b/java/30_insert.ipynb @@ -121,15 +121,8 @@ "source": [ "Document bookFrom1500 = new Document(\"year\", 1500);\n", "\n", - "FindIterable cursor = books.find(bookFrom1500);\n", - "\n", - "if (cursor != null) {\n", - " for(Document b: cursor) {\n", - " System.out.println(\"Book: \" + b.toJson());\n", - " }\n", - "} else {\n", - " System.out.println(\"Empty collection\");\n", - "}" + "books.find(bookFrom1500)\n", + " .forEach(b -> System.out.println(\"Book: \" + b.toJson()));" ] }, { @@ -153,15 +146,8 @@ "source": [ "Document bookFrom1500 = new Document(\"_id\", new ObjectId(\"\")); // add the _id here!\n", "\n", - "FindIterable cursor = books.find(bookFrom1500);\n", - "\n", - "if (cursor != null) {\n", - " for(Document b: cursor) {\n", - " System.out.println(\"Book: \" + b.toJson());\n", - " }\n", - "} else {\n", - " System.out.println(\"Empty collection\");\n", - "}" + "books.find(bookFrom1500)\n", + " .forEach(b -> System.out.println(\"Book: \" + b.toJson()));" ] }, { diff --git a/java/40_delete.ipynb b/java/40_delete.ipynb index 59a00ce..3beecb5 100644 --- a/java/40_delete.ipynb +++ b/java/40_delete.ipynb @@ -121,15 +121,8 @@ "source": [ "Document bookFrom1500 = new Document(\"_id\", \"platero\"); \n", "\n", - "FindIterable cursor = books.find(bookFrom1500);\n", - "\n", - "if (cursor != null) {\n", - " for(Document b: cursor) {\n", - " System.out.println(\"Book: \" + b.toJson());\n", - " }\n", - "} else {\n", - " System.out.println(\"Empty collection\");\n", - "}" + "books.find(bookFrom1500)\n", + " .forEach(b -> System.out.println(\"Book: \" + b.toJson())); " ] }, { diff --git a/java/50_update.ipynb b/java/50_update.ipynb index f96e204..e038f4a 100644 --- a/java/50_update.ipynb +++ b/java/50_update.ipynb @@ -121,15 +121,8 @@ "source": [ "Document elQuijote = new Document(\"_id\", \"quijote\"); \n", "\n", - "FindIterable cursor = books.find(elQuijote);\n", - "\n", - "if (cursor != null) {\n", - " for(Document b: cursor) {\n", - " System.out.println(\"Book: \" + b.toJson());\n", - " }\n", - "} else {\n", - " System.out.println(\"Empty collection\");\n", - "}" + "books.find(elQuijote)\n", + " .forEach(b -> System.out.println(\"Book: \" + b.toJson())); " ] }, {