You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
-[x] Use $unwind stages to ensure a single prize affiliation country per pipeline document.
142
+
-[x] Filter out prize-affiliation-country values that are "empty" (null, not present, etc.) -- ensure values are "$in" the list of known values.
143
+
-[x] Produce a count of documents for each value of "affilCountrySameAsBorn" (a field we've projected for you using the $indexOfBytes operator) by adding 1 to the running sum.
144
+
```py
145
+
key_ac ="prizes.affiliations.country"
146
+
key_bc ="bornCountry"
147
+
pipeline = [
148
+
{"$project": {key_bc: 1, key_ac: 1}},
149
+
150
+
# Ensure a single prize affiliation country per pipeline document
151
+
{"$unwind": "$prizes"},
152
+
{"$unwind": "$prizes.affiliations"},
153
+
154
+
# Ensure values in the list of distinct values (so not empty)
# Count by "$affilCountrySameAsBorn" value (True or False)
160
+
{"$group": {"_id": "$affilCountrySameAsBorn",
161
+
"count": {"$sum": 1 }}},
162
+
]
163
+
for doc in db.laureates.aggregate(pipeline): print(doc)
164
+
```
165
+
## 🦍 Countries of birth by prize category
166
+
-[x] $unwind the laureates array field to output one pipeline document for each array element.
167
+
-[x] After pulling in laureate bios with a $lookup stage, unwind the new laureate_bios array field (each laureate has only a single biography document).
168
+
-[x] Collect the set of bornCountries associated with each prize category.
169
+
-[x] Project out the size of each category's set of bornCountries.
0 commit comments