Skip to content

Commit 1f400e1

Browse files
committed
Clean up some of the code for pymongo changes (chapter 5, pymongo direct API)
1 parent 44d0027 commit 1f400e1

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

src/05_pymongo/play_around_pymongo/program.py

+9-5
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,10 @@
55

66
db = client.the_small_bookstore
77

8-
# NOTE: In the video we use db.books.count(), it's been deprecated for more explicit
9-
# versions. See
10-
# https://api.mongodb.com/python/current/api/pymongo/collection.html#pymongo.collection.Collection.estimated_document_count
8+
# NOTE: In the video we use db.books.count(), it's been deprecated for more explicit versions. See
9+
# https://pymongo.readthedocs.io/en/stable/api/pymongo/collection.html#pymongo.collection.Collection.count_documents
1110
# for details
12-
13-
if db.books.estimated_document_count() == 0:
11+
if db.books.count_documents({}) == 0:
1412
print("Inserting data")
1513
# insert some data...
1614
r = db.books.insert_one({'title': 'The third book', 'isbn': '73738584947384'})
@@ -24,7 +22,13 @@
2422
# # print(book, type(book))
2523
# # book['favorited_by'] = []
2624
# book['favorited_by'].append(100)
25+
26+
# Updated from recording, was:
2727
# db.books.update({'_id': book.get('_id')}, book)
28+
#
29+
# pymongo now requires update_one with the $set operator:
30+
# db.books.update_one({'_id': book.get('_id')}, {"$set": book})
31+
2832
# book = db.books.find_one({'isbn': '73738584947384'})
2933
# print(book)
3034

0 commit comments

Comments
 (0)