Skip to content

Commit 862c6f2

Browse files
authored
Update 3. Get Only What You Need, and Fast.md
1 parent 9ab5099 commit 862c6f2

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,3 +92,19 @@ for prize in prizes:
9292
![image](https://user-images.githubusercontent.com/51888893/204381868-7de20ade-488a-454d-91a2-f887495106e0.png)
9393
### 📚 Primary and secondary sorting
9494
![image](https://user-images.githubusercontent.com/51888893/204382060-571d2118-4469-4142-bd7f-f3005f853ffb.png)
95+
96+
## :gorilla What the sort?
97+
> This block prints out the first five projections of a sorted query. What "sort" argument fills the blank?
98+
```py
99+
docs = list(db.laureates.find(
100+
{"born": {"$gte": "1900"}, "prizes.year": {"$gte": "1954"}},
101+
{"born": 1, "prizes.year": 1, "_id": 0},
102+
sort=____))
103+
for doc in docs[:5]:
104+
print(doc)
105+
```
106+
{'born': '1916-08-25', 'prizes': [{'year': '1954'}]}
107+
{'born': '1915-06-15', 'prizes': [{'year': '1954'}]}
108+
{'born': '1901-02-28', 'prizes': [{'year': '1954'}, {'year': '1962'}]}
109+
{'born': '1913-07-12', 'prizes': [{'year': '1955'}]}
110+
{'born': '1911-01-26', 'prizes': [{'year': '1955'}]}

0 commit comments

Comments
 (0)