Skip to content

Commit 6ce5f38

Browse files
committed
Fix/ exercises
1 parent 0418190 commit 6ce5f38

1 file changed

Lines changed: 34 additions & 6 deletions

File tree

‎python/100_aggregation_pipeline_match.ipynb‎

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,8 @@
7272
"cell_type": "markdown",
7373
"metadata": {},
7474
"source": [
75-
"### Exercise: get all books from 2010 or 2012"
75+
"### Exercise: get all books from 2010 or 2012 and with less than 200 pages\n",
76+
"Use { $and: [ {field: value1}, {field: value2} ] } to express field == value1 AND field == value2 Hint: use Less Than {field: {$lt: value}}"
7677
]
7778
},
7879
{
@@ -83,17 +84,44 @@
8384
"source": [
8485
"books_from_2010_and_2012 = [\n",
8586
" {\n",
86-
" \"$match\": { \"year\": { \"$in\": [2010, 2012] } }\n",
87-
" },\n",
87+
" \"$match\": {\n",
88+
" # add code here!\n",
89+
" } \n",
90+
" }\n",
91+
"]\n",
92+
"\n",
93+
"cursor = books.aggregate(books_from_2010_and_2012)\n",
94+
"\n",
95+
"for f in cursor:\n",
96+
" print(f)"
97+
]
98+
},
99+
{
100+
"cell_type": "markdown",
101+
"metadata": {},
102+
"source": [
103+
"### Exercise: get all books from 2010 or all books with less than 50 pages\n",
104+
"Use { $or: [ {field: value1}, {field: value2} ] } to express field == value1 OR field == value2"
105+
]
106+
},
107+
{
108+
"cell_type": "code",
109+
"execution_count": null,
110+
"metadata": {},
111+
"outputs": [],
112+
"source": [
113+
"books_from_2010_or_2012 = [\n",
88114
" {\n",
89-
" \"$limit\": 10\n",
115+
" \"$match\": {\n",
116+
" # add code here!\n",
117+
" } \n",
90118
" }\n",
91119
"]\n",
92120
"\n",
93-
"cursor = books.aggregate(pipeline)\n",
121+
"cursor = books.aggregate(books_from_2010_or_2012)\n",
94122
"\n",
95123
"for f in cursor:\n",
96-
" print(f\"{f}.\")"
124+
" print(f)"
97125
]
98126
},
99127
{

0 commit comments

Comments
 (0)