Skip to content

Commit 5529cb0

Browse files
authored
Update 4. Aggregation Pipelines: Let the Server Do It For You.md
1 parent 6c1dc01 commit 5529cb0

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

Introduction to MongoDB in Python/4. Aggregation Pipelines: Let the Server Do It For You.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,3 +67,17 @@ for key, group in groupby(cursor, key=itemgetter("year")):
6767
print("{year}: {missing}".format(
6868
year=key, missing=", ".join(sorted(missing))))
6969
```
70+
## 🦍 Field Paths and Sets
71+
Previously, we confirmed -- via a Python loop -- that for each prize, either all laureates have a 1/3 share, or none do. Now, let's do this via an aggregation (result should be an empty list):
72+
73+
list(db.prizes.aggregate([
74+
{"$project": {"allThree": {"$setEquals": [____, ____]},
75+
"noneThree": {"$not": {"$setIsSubset": [____, ____]}}}},
76+
{"$match": {"$nor": [{"allThree": True}, {"noneThree": True}]}}]))
77+
> Which values fill the blanks?
78+
79+
Possible Answers
80+
- [ ] "$laureates.share", ["3"], ["3"], "$laureates.share"
81+
- [ ] "laureates.share", ["3"], ["3"], "laureates.share"
82+
- [ ] "laureates.share", {"3"}, {"3"}, "laureates.share"
83+
- [ ] "$laureates.share", {"3"}, {"3"}, "$laureates.share"

0 commit comments

Comments
 (0)