Skip to content

Commit d5c972a

Browse files
refactor: improve group example wording and formatting
1 parent 8fa7e65 commit d5c972a

1 file changed

Lines changed: 8 additions & 3 deletions

File tree

java/104_aggregation_pipeline_group_by.ipynb

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
"import com.mongodb.client.model.Filters;\n",
4747
"\n",
4848
"import static com.mongodb.client.model.Sorts.descending;\n",
49+
"import static com.mongodb.client.model.Aggregates.limit;\n",
4950
"\n",
5051
"import org.bson.Document;\n",
5152
"import java.util.Arrays;\n",
@@ -78,7 +79,7 @@
7879
"source": [
7980
"## $group\n",
8081
"\n",
81-
"`$group` groups books by `year` and calculates the total number of pages for each group."
82+
"Use `$group` to group books by `year` and calculate the total number of pages for each year and limit in 5 results."
8283
]
8384
},
8485
{
@@ -89,8 +90,12 @@
8990
"outputs": [],
9091
"source": [
9192
"AggregateIterable<Document> result = books.aggregate(\n",
92-
" Arrays.asList(\n",
93-
" Aggregates.group(\"$year\", Accumulators.sum(\"totalPages\", \"$pages\"))\n",
93+
" List.of(\n",
94+
" Aggregates.group(\n",
95+
" \"$year\",\n",
96+
" Accumulators.sum(\"totalPages\", \"$pages\")\n",
97+
" ),\n",
98+
" limit(5)\n",
9499
" )\n",
95100
");\n",
96101
"\n",

0 commit comments

Comments
 (0)