Skip to content

Commit 0f5e8b7

Browse files
committed
Fixed genres array name / structure
1 parent cb6e54c commit 0f5e8b7

File tree

4 files changed

+60
-39
lines changed

4 files changed

+60
-39
lines changed

javascript/101_aggregation_pipeline_arrays.ipynb

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -79,13 +79,17 @@
7979
"source": [
8080
"// Aggregation pipeline\n",
8181
"const pipeline = [\n",
82-
" { $match: {\n",
83-
" 'genre.name': { $all: ['Police', 'Fiction'] }\n",
84-
" } },\n",
85-
" { $project: {\n",
86-
" title: 1,\n",
87-
" genre: 1\n",
88-
" } }\n",
82+
" {\n",
83+
" $match: {\n",
84+
" genres: { $all: [\"Police\", \"Fiction\"] },\n",
85+
" },\n",
86+
" },\n",
87+
" {\n",
88+
" $project: {\n",
89+
" title: 1,\n",
90+
" genre: 1,\n",
91+
" },\n",
92+
" },\n",
8993
"];\n",
9094
"\n",
9195
"// Execute the aggregate operation\n",
@@ -114,13 +118,17 @@
114118
"source": [
115119
"// Aggregate pipeline\n",
116120
"const pipeline = [\n",
117-
" { $match: {\n",
118-
" 'genre.name': { $in: ['Police', 'Fiction'] }\n",
119-
" } },\n",
120-
" { $project: {\n",
121-
" title: 1,\n",
122-
" genre: 1\n",
123-
" } }\n",
121+
" {\n",
122+
" $match: {\n",
123+
" genres: { $in: [\"Police\", \"Fiction\"] },\n",
124+
" },\n",
125+
" },\n",
126+
" {\n",
127+
" $project: {\n",
128+
" title: 1,\n",
129+
" genre: 1,\n",
130+
" },\n",
131+
" },\n",
124132
"];\n",
125133
"\n",
126134
"// Execute the aggregate operation\n",
@@ -146,7 +154,7 @@
146154
"name": "typescript",
147155
"nbconvert_exporter": "script",
148156
"pygments_lexer": "typescript",
149-
"version": "5.8.3"
157+
"version": "5.9.2"
150158
}
151159
},
152160
"nbformat": 4,

javascript/102_aggregation_pipeline_unwind.ipynb

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -78,14 +78,18 @@
7878
"source": [
7979
"// Aggregation pipeline\n",
8080
"const pipeline = [\n",
81-
" { $match: {\n",
82-
" \"_id\": \"60187778\"\n",
83-
" } },\n",
84-
" { $unwind: \"$attributes\" },\n",
85-
" { $project: {\n",
86-
" title: 1,\n",
87-
" attributes: 1\n",
88-
" } }\n",
81+
" {\n",
82+
" $match: {\n",
83+
" _id: \"0060930284\",\n",
84+
" },\n",
85+
" },\n",
86+
" { $unwind: \"$attributes\" },\n",
87+
" {\n",
88+
" $project: {\n",
89+
" title: 1,\n",
90+
" attributes: 1,\n",
91+
" },\n",
92+
" },\n",
8993
"];\n",
9094
"\n",
9195
"// Execute the aggregate operation\n",

javascript/103_aggregation_pipeline_lookup.ipynb

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"id": "3b936925-e295-489a-b508-2b99c0160217",
1414
"metadata": {},
1515
"source": [
16-
"# Aggregation Pipeline\n",
16+
"# Aggregation Pipeline - $lookup\n",
1717
" "
1818
]
1919
},
@@ -77,14 +77,23 @@
7777
"source": [
7878
"// Aggregation pipeline\n",
7979
"const pipeline = [\n",
80-
" {$lookup: {\n",
81-
" from: \"books\", // read from books collection\n",
82-
" localField: \"books\", // authors have a books array with books ids\n",
83-
" foreignField: \"_id\", // join using the _id field\n",
84-
" as: \"booksWritten\" // add a new field with the results\n",
85-
" } },\n",
86-
" {$limit: 10},\n",
87-
" {$project: {_id: 0}}\n",
80+
" {\n",
81+
" $lookup: {\n",
82+
" from: \"books\", // read from books collection\n",
83+
" localField: \"books\", // authors have a books array with books ids\n",
84+
" foreignField: \"_id\", // join using the _id field\n",
85+
" as: \"booksWritten\", // add a new field with the results\n",
86+
" },\n",
87+
" },\n",
88+
" { $limit: 10 },\n",
89+
" {\n",
90+
" $project: {\n",
91+
" _id: 0,\n",
92+
" title: 1,\n",
93+
" books: 1,\n",
94+
" booksWritten: 1,\n",
95+
" },\n",
96+
" },\n",
8897
"];\n",
8998
"\n",
9099
"// Execute the aggregate operation\n",

javascript/11_find_arrays.ipynb

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@
7676
"outputs": [],
7777
"source": [
7878
"const cursor = await books.find(\n",
79-
"\t{ \"genre.name\": \"Poetry\"}\n",
79+
"\t{ \"genres\": \"Poetry\"}\n",
8080
")\n",
8181
"\n",
8282
"await cursor.forEach((book) => {\n",
@@ -100,15 +100,15 @@
100100
"outputs": [],
101101
"source": [
102102
"const cursor = await books.find(\n",
103-
"\t{ \"genre.name\": { $all: [\n",
104-
" \"Poetry\",\n",
103+
"\t{ \"genres\": { $all: [\n",
104+
" \"Family Life\",\n",
105105
" \"Fiction\"\n",
106106
" ]}\n",
107107
" }\n",
108108
")\n",
109109
"\n",
110110
"await cursor.forEach((book) => {\n",
111-
" console.log(book.title + \" - \" + JSON.stringify(book.genre));\n",
111+
" console.log(book.title + \" - \" + JSON.stringify(book.genres));\n",
112112
"});\n"
113113
]
114114
},
@@ -128,15 +128,15 @@
128128
"outputs": [],
129129
"source": [
130130
"const cursor = await books.find(\n",
131-
"\t{ \"genre.name\": { $in: [\n",
131+
"\t{ \"genres\": { $in: [\n",
132132
" \"Poetry\",\n",
133133
" \"Fiction\"\n",
134134
" ]}\n",
135135
" }\n",
136136
")\n",
137137
"\n",
138138
"await cursor.forEach((book) => {\n",
139-
" console.log(book.title + \" - \" + JSON.stringify(book.genre));\n",
139+
" console.log(book.title + \" - \" + JSON.stringify(book.genres));\n",
140140
"});"
141141
]
142142
},
@@ -158,7 +158,7 @@
158158
"outputs": [],
159159
"source": [
160160
"const cursor = await books.find(\n",
161-
"\t{ \"genre.name\": [\n",
161+
"\t{ \"genres\": [\n",
162162
" \"Poetry\",\n",
163163
" \"Fiction\"\n",
164164
" ]}\n",

0 commit comments

Comments
 (0)