Skip to content

Commit 8305637

Browse files
authored
Update 3. Get Only What You Need, and Fast.md
1 parent 2339401 commit 8305637

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

Introduction to MongoDB in Python/3. Get Only What You Need, and Fast.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,3 +247,17 @@ five_most_common = Counter(n_born_and_affiliated).most_common(5)
247247
print(five_most_common)
248248
```
249249
[('USA', 241), ('United Kingdom', 56), ('France', 26), ('Germany', 19), ('Japan', 17)]
250+
251+
## 🦍 Setting a new limit?
252+
> How many documents does the following expression return?
253+
254+
list(db.prizes.find({"category": "economics"},
255+
{"year": 1, "_id": 0})
256+
.sort("year")
257+
.limit(3)
258+
.limit(5))
259+
Possible Answers
260+
- [ ] 3: the first call to limit takes precedence
261+
- [x] 5: the second call to limit overrides the first
262+
- [ ] none: instead, an error is raised
263+
> reason : You can think of the query parameters as being updated like a dictionary in Python: `d = {'limit': 3}; d.update({'limit': 5}); print(d) will print "{'limit': 5}"`

0 commit comments

Comments
 (0)