Skip to content

Commit 43cd36a

Browse files
committed
Fix indentation and lint
1 parent c9ab72e commit 43cd36a

File tree

10 files changed

+113
-104
lines changed

10 files changed

+113
-104
lines changed

docs/40-CRUD/1-WHERE.mdx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,10 @@ Now, translate the following into a MongoDB query.
135135
```python
136136
books_with_total_inventory_of_5 = books.find({"totalInventory": 5})
137137

138-
for book in books_with_total_inventory_of_5:
139-
print(f"Book Title: {book['title']} - Total Inventory: {book['totalInventory']}")
138+
for book in books_with_total_inventory_of_5:
139+
title = book['title']
140+
inventory = book['totalInventory']
141+
print(f"Book Title: {title} - Total Inventory: {inventory}")
140142
```
141143
</div>
142144
</TabItem>
@@ -189,8 +191,8 @@ for book in books_with_total_inventory_of_5:
189191
```python
190192
books_with_more_than_300_pages = books.find({"pages": {"$gt": 300}})
191193

192-
for book in books_with_more_than_300_pages:
193-
print(f"Book Title: {book['title']} - Pages: {book['pages']}")
194+
for book in books_with_more_than_300_pages:
195+
print(f"Book Title: {book['title']} - Pages: {book['pages']}")
194196
```
195197
</div>
196198
</TabItem>

docs/40-CRUD/2-SELECT.mdx

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -124,10 +124,12 @@ Here:
124124
<TabItem value="python" label="Python">
125125
<div>
126126
```python
127-
books_with_title_only = books.find({}, {"title": 1, "_id": 0}).limit(10)
127+
books_with_title_only = books.find(
128+
{}, {"title": 1, "_id": 0}
129+
).limit(10)
128130

129-
for book in books_with_title_only:
130-
print(book)
131+
for book in books_with_title_only:
132+
print(book)
131133
```
132134
</div>
133135
</TabItem>
@@ -177,16 +179,18 @@ for book in books_with_title_only:
177179
{
178180
Console.WriteLine("Empty Collection");
179181
}
180-
```
182+
```
181183
</div>
182184
</TabItem>
183185
<TabItem value="python" label="Python">
184186
<div>
185187
```python
186-
books_with_genre_history = books.find({"genres": "History"}, {"_id": 0, "authors": 0}).limit(10)
188+
books_with_genre_history = books.find(
189+
{"genres": "History"}, {"_id": 0, "authors": 0}
190+
).limit(10)
187191

188-
for book in books_with_genre_history:
189-
print(book)
192+
for book in books_with_genre_history:
193+
print(book)
190194
```
191195
</div>
192196
</TabItem>

docs/40-CRUD/3-ORDER-LIMIT.mdx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,12 +102,12 @@ This returns the **top 10 available books** in the "Science Fiction" genre.
102102
<TabItem value="python" label="Python">
103103
<div>
104104
```python
105-
books_sorted_by_title = books.find({}).sort("title", 1).limit(10)
105+
books_sorted_by_title = books.find({}).sort("title", 1).limit(10)
106106

107-
for book in books_sorted_by_title:
108-
print(book)
107+
for book in books_sorted_by_title:
108+
print(book)
109109
```
110-
</div>
110+
</div>
111111
</TabItem>
112112
</Tabs>
113113
</details>

docs/40-CRUD/4-INSERT-DELETE.mdx

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -155,34 +155,34 @@ DELETE FROM reviews WHERE bookId = '0786222727';
155155
<div>
156156
```python
157157
reviews = db["reviews"]
158-
reviews.insert_many([
159-
{
160-
"text": "Thrilling end.",
161-
"rating": 4,
162-
"name": "Mark",
163-
"bookId": "0786222727",
164-
},
165-
{
166-
"text": "Must read!",
167-
"rating": 5,
168-
"name": "Raj",
169-
"bookId": "0786222727",
170-
},
171-
{
172-
"text": "Very expensive",
173-
"rating": 3,
174-
"name": "Yun",
175-
"bookId": "0786222727",
176-
},
177-
{
178-
"text": "Extremely satisfied with the storyline!",
179-
"rating": 5,
180-
"name": "Lisa",
181-
"bookId": "0786222727",
182-
}
158+
reviews.insert_many([
159+
{
160+
"text": "Thrilling end.",
161+
"rating": 4,
162+
"name": "Mark",
163+
"bookId": "0786222727",
164+
},
165+
{
166+
"text": "Must read!",
167+
"rating": 5,
168+
"name": "Raj",
169+
"bookId": "0786222727",
170+
},
171+
{
172+
"text": "Very expensive",
173+
"rating": 3,
174+
"name": "Yun",
175+
"bookId": "0786222727",
176+
},
177+
{
178+
"text": "Extremely satisfied with the storyline!",
179+
"rating": 5,
180+
"name": "Lisa",
181+
"bookId": "0786222727",
182+
}
183183
])
184184
```
185-
</div>
185+
</div>
186186
</TabItem>
187187
</Tabs>
188188
</details>
@@ -222,7 +222,7 @@ reviews.insert_many([
222222
<div>
223223
```python
224224
reviews = db["reviews"]
225-
reviews.delete_many({"bookId": "0786222727"})
225+
reviews.delete_many({"bookId": "0786222727"})
226226
```
227227
</div>
228228
</TabItem>

docs/40-CRUD/5-UPDATE.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ Executing the above command will insert a fresh new document in the collection,
123123
<div>
124124
```python
125125
books = db["books"]
126-
books.update_one(
126+
books.update_one(
127127
{"title": "Treasure of the Sun"},
128128
{"$set": {"pages": 449}}
129129
)

docs/50-aggregation/2-match-project.mdx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -144,10 +144,10 @@ db.books.aggregate([
144144
<div>
145145
```python
146146
books_two_copies = books.aggregate([
147-
{ "$match": { "available": { "$gt": 2 } } }
147+
{"$match": {"available": {"$gt": 2}}}
148148
])
149149

150-
for book in books_two_copies:
150+
for book in books_two_copies:
151151
print(book)
152152
```
153153
</div>
@@ -211,10 +211,10 @@ for book in books_two_copies:
211211
{ "$project": { "title": 1, "year": 1, "_id": 0 } }
212212
])
213213

214-
for book in books_two_copies:
214+
for book in books_two_copies:
215215
print(f"Title: {book['title']} - Publication Year: {book['year']}")
216216
```
217-
</div>
217+
</div>
218218
</TabItem>
219219
</Tabs>
220220
</details>

docs/50-aggregation/3-sort-limit.mdx

Lines changed: 33 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -193,45 +193,47 @@ Learn [when to use $addFields over $project](https://www.practical-mongodb-aggre
193193
<TabItem value="project" label="Using $project">
194194
<div>
195195
```python
196-
most_authors = books.aggregate([
196+
most_authors = books.aggregate
197+
([
197198
{ "$match": { "year": { "$gt": 2000 } } },
198-
{ "$match": { "authors": { "$exists": True } } },
199-
{
200-
"$project": {
201-
"title": 1,
202-
"year": 1,
203-
"authors": 1,
204-
"numAuthors": { "$size": "$authors" }
205-
}
206-
},
207-
{ "$sort": { "numAuthors": -1 } },
208-
{ "$limit": 1 }
209-
])
210-
211-
for book in most_authors:
212-
print(book)
213-
```
199+
{ "$match": { "authors": { "$exists": True } } },
200+
{
201+
"$project": {
202+
"title": 1,
203+
"year": 1,
204+
"authors": 1,
205+
"numAuthors": { "$size": "$authors" }
206+
}
207+
},
208+
{ "$sort": { "numAuthors": -1 } },
209+
{ "$limit": 1 }
210+
])
211+
212+
for book in most_authors:
213+
print(book)
214+
```
214215
</div>
215216
</TabItem>
216217

217218
<TabItem value="addFields" label="Using $addFields">
218219
<div>
219220
```python
220-
most_authors = books.aggregate([
221+
most_authors = books.aggregate
222+
([
221223
{ "$match": { "year": { "$gt": 2000 } } },
222-
{ "$match": { "authors": { "$exists": True } } },
223-
{
224-
"$addFields": {
225-
"numAuthors": { "$size": "$authors" }
226-
}
227-
},
228-
{ "$sort": { "numAuthors": -1 } },
229-
{ "$limit": 1 }
230-
])
231-
232-
for book in most_authors:
233-
print(book)
234-
```
224+
{ "$match": { "authors": { "$exists": True } } },
225+
{
226+
"$addFields": {
227+
"numAuthors": { "$size": "$authors" }
228+
}
229+
},
230+
{ "$sort": { "numAuthors": -1 } },
231+
{ "$limit": 1 }
232+
])
233+
234+
for book in most_authors:
235+
print(book)
236+
```
235237
</div>
236238
</TabItem>
237239
</Tabs>

docs/50-aggregation/4-group.mdx

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -178,16 +178,16 @@ GROUP BY year;
178178
<div>
179179
```python
180180
books_with_avg_rating = reviews.aggregate([
181-
{
182-
"$group": {
183-
"_id": "$bookId",
184-
"avgRating": { "$avg": "$rating" }
181+
{
182+
"$group": {
183+
"_id": "$bookId",
184+
"avgRating": {"$avg": "$rating"}
185+
}
185186
}
186-
}
187187
])
188188

189-
for book in books_with_avg_rating:
190-
print(book)
189+
for book in books_with_avg_rating:
190+
print(book)
191191
```
192192
</div>
193193
</TabItem>
@@ -289,19 +289,19 @@ for book in books_with_avg_rating:
289289
<div>
290290
```python
291291
reviewers_count = reviews.aggregate([
292-
{
293-
"$group": {
294-
"_id": "$name",
295-
"totalReviews": { "$sum": 1 }
292+
{
293+
"$group": {
294+
"_id": "$name",
295+
"totalReviews": {"$sum": 1}
296+
}
297+
},
298+
{
299+
"$sort": {"totalReviews": -1}
296300
}
297-
},
298-
{
299-
"$sort": { "totalReviews": -1 }
300-
}
301301
])
302302

303-
for reviewer in reviewers_count:
304-
print(reviewer)
303+
for reviewer in reviewers_count:
304+
print(reviewer)
305305
```
306306
</div>
307307
</TabItem>
@@ -310,13 +310,13 @@ for reviewer in reviewers_count:
310310
<div>
311311
```python
312312
reviewers_count = reviews.aggregate([
313-
{
314-
"$sortByCount": "$name"
315-
}
313+
{
314+
"$sortByCount": "$name"
315+
}
316316
])
317317

318-
for reviewer in reviewers_count:
319-
print(reviewer)
318+
for reviewer in reviewers_count:
319+
print(reviewer)
320320
```
321321
</div>
322322
</TabItem>

docs/50-aggregation/5-lookup.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ The $lookup operation creates an array within each book document. Using $unwind
151151
<TabItem value="python" label="Python">
152152
<div>
153153
```python
154-
books_with_reviews = books.aggregate([
154+
books_with_reviews = books.aggregate([
155155
{
156156
"$lookup":
157157
{

docs/50-aggregation/7-merge.mdx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,8 @@ ON DUPLICATE KEY UPDATE totalBooks = VALUES(totalBooks);
211211
<TabItem value="authors" label="through authors collection">
212212
```python
213213
authors_collection = db.authors
214-
author_stats = authors_collection.aggregate([
214+
author_stats = authors_collection.aggregate
215+
([
215216
{ "$unwind": "$books" },
216217
{ "$group": { "_id": "$name", "totalBooks": { "$sum": 1 } } },
217218
{ "$merge": {
@@ -224,8 +225,8 @@ author_stats = authors_collection.aggregate([
224225
])
225226
```
226227
</TabItem>
227-
</Tabs>
228-
</TabItem>
228+
</Tabs>
229+
</TabItem>
229230
</Tabs>
230231
</div>
231232
</details>

0 commit comments

Comments
 (0)