Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Simplify $match aggregation example using exact title filter
  • Loading branch information
ricardohsmello committed May 8, 2026
commit a865451b9e713176e63b16f4f313654772c30ad9
9 changes: 5 additions & 4 deletions java/100_aggregation_pipeline_match.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
"import com.mongodb.client.model.Projections;\n",
"\n",
"import static com.mongodb.client.model.Filters.gt;\n",
"import static com.mongodb.client.model.Filters.eq;\n",
"import static com.mongodb.client.model.Projections.include;\n",
"import static com.mongodb.client.model.Projections.excludeId;\n",
"import static com.mongodb.client.model.Projections.fields;\n",
Expand Down Expand Up @@ -93,7 +94,7 @@
"source": [
"## $match\n",
"\n",
"We’ll return all books published after 2010 using $match for filtering and $project to return only specific fields."
"We’ll use $match to return only the book with the title \"Treasure of the Sun\"."
]
},
{
Expand All @@ -107,14 +108,14 @@
},
"outputs": [],
"source": [
"Bson yearFilter = gt(\"year\", 2010);\n",
"Bson matchStage = match(yearFilter);\n",
"\n",
"Bson titleFilter = eq(\"title\", \"Treasure of the Sun\");\n",
"Bson matchStage = match(titleFilter);\n",
"List<Bson> aggregationPipeline = List.of(matchStage);\n",
"\n",
"AggregateIterable<Document> result = books.aggregate(aggregationPipeline);\n",
"\n",
"// Iterate through the results\n",
"\n",
"for (Document doc : result) {\n",
" System.out.println(\"book: \" + doc.toJson());\n",
"}"
Expand Down