From 44a141686b010beb8cbccd7bd03817fc5a53f32f Mon Sep 17 00:00:00 2001 From: Ricardo Mello Date: Thu, 11 Dec 2025 18:37:46 -0300 Subject: [PATCH 1/3] feat: Add Java implementations for find queries, including exact match, range filtering, and combined conditions --- docs/40-CRUD/1-WHERE.mdx | 59 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) diff --git a/docs/40-CRUD/1-WHERE.mdx b/docs/40-CRUD/1-WHERE.mdx index 751bee8..ee54ef3 100644 --- a/docs/40-CRUD/1-WHERE.mdx +++ b/docs/40-CRUD/1-WHERE.mdx @@ -129,6 +129,25 @@ Now, translate the following into a MongoDB query. } ``` + +
+ ```Java + Bson filter = eq("totalInventory", 5); + + Bson projection = Projections.fields( + Projections.include("title", "year", "totalInventory")); + + List results = books.find(filter) + .projection(projection) + .into(new ArrayList<>()); + + if (results.isEmpty()) { + System.out.println("No books were found for the given query."); + } else { + results.forEach(doc -> System.out.println(doc.toJson())); + } + ``` +
@@ -173,6 +192,25 @@ Now, translate the following into a MongoDB query. } ``` + +
+ ```Java + Bson filter = gt("pages", 300); + + Bson projection = Projections.fields( + Projections.include("title", "genres", "pages")); + + List results = books.find(filter) + .projection(projection) + .into(new ArrayList<>()); + + if (results.isEmpty()) { + System.out.println("No books were found for the given query."); + } else { + results.forEach(doc -> System.out.println(doc.toJson())); + } + ``` +
@@ -224,6 +262,27 @@ Now, translate the following into a MongoDB query. } ``` + +
+ ```Java + Bson filter = and( + eq("genres", "Science"), + gt("pages", 300)); + + Bson projection = Projections.fields( + Projections.include("title", "genres", "pages")); + + List results = books.find(filter) + .projection(projection) + .into(new ArrayList<>()); + + if (results.isEmpty()) { + System.out.println("No books were found for the given query."); + } else { + results.forEach(doc -> System.out.println(doc.toJson())); + } + ``` +
From 3ede9b07756ac41d0febb0ff0734263c01e23957 Mon Sep 17 00:00:00 2001 From: Ricardo Mello Date: Fri, 12 Dec 2025 10:51:24 -0300 Subject: [PATCH 2/3] feat: Add Java examples demonstrating document insertion with basic and structured fields --- docs/40-CRUD/4-INSERT-DELETE.mdx | 43 +++++++++++++++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) diff --git a/docs/40-CRUD/4-INSERT-DELETE.mdx b/docs/40-CRUD/4-INSERT-DELETE.mdx index c983d9b..348cceb 100644 --- a/docs/40-CRUD/4-INSERT-DELETE.mdx +++ b/docs/40-CRUD/4-INSERT-DELETE.mdx @@ -150,7 +150,34 @@ DELETE FROM reviews WHERE bookId = '0786222727'; reviewsCollection.InsertMany(newReviews); ``` - + +
+ ```Java + var reviews = library.getCollection("reviews"); + + reviews.insertMany(List.of( + new Document("text", "Thrilling end.") + .append("rating", 4) + .append("name", "Mark") + .append("bookId", "0786222727"), + + new Document("text", "Very expensive") + .append("rating", 3) + .append("name", "Yun") + .append("bookId", "0786222727"), + + new Document("text", "Must read!.") + .append("rating", 6) + .append("name", "Raj") + .append("bookId", "0786222727"), + + new Document("text", "Extremely satisfied with the storyline!") + .append("rating", 5) + .append("name", "Lisa") + .append("bookId", "0786222727"))); + ``` +
+
@@ -184,6 +211,20 @@ DELETE FROM reviews WHERE bookId = '0786222727'; Console.WriteLine($"{deletionResult.DeletedCount} review(s) deleted."); ``` + +
+ ```Java + import static com.mongodb.client.model.Filters.eq; + import org.bson.conversions.Bson; + + MongoCollection reviews = library.getCollection("reviews"); + + Bson filter = eq("bookId", "0786222727"); + + DeleteResult result = reviews.deleteMany(filter); + System.out.println(result.getDeletedCount() + " reviews deleted."); + ``` +
From bafe0665cec22072faaa0c57b448793040272403 Mon Sep 17 00:00:00 2001 From: Ricardo Mello Date: Fri, 12 Dec 2025 10:51:42 -0300 Subject: [PATCH 3/3] feat: Implement Java update operations --- docs/40-CRUD/5-UPDATE.mdx | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/docs/40-CRUD/5-UPDATE.mdx b/docs/40-CRUD/5-UPDATE.mdx index f92d422..22ebfd2 100644 --- a/docs/40-CRUD/5-UPDATE.mdx +++ b/docs/40-CRUD/5-UPDATE.mdx @@ -118,6 +118,17 @@ Executing the above command will insert a fresh new document in the collection, Console.WriteLine($"Matched: {result.MatchedCount}, Modified: {result.ModifiedCount}"); ``` + +
+ ```Java + import static com.mongodb.client.model.Filters.eq; + + var query = eq("title", "Treasure of the Sun"); + var update = Updates.set("pages", 449); + UpdateResult updateResult = books.updateOne(query, update); + System.out.println("Modified document count: " + updateResult.getModifiedCount()); + ``` +