Fixes #9 - Some commands are deprecated.

master
Michael Kennedy 5 years ago
parent 4997e05eab
commit 2bfe78fc8f

@ -5,7 +5,12 @@ client = pymongo.MongoClient(conn_str)
db = client.the_small_bookstore db = client.the_small_bookstore
if db.books.count() == 0: # NOTE: In the video we use db.books.count(), it's been deprecated for more explicit
# versions. See
# https://api.mongodb.com/python/current/api/pymongo/collection.html#pymongo.collection.Collection.estimated_document_count
# for details
if db.books.estimated_document_count() == 0:
print("Inserting data") print("Inserting data")
# insert some data... # insert some data...
r = db.books.insert_one({'title': 'The third book', 'isbn': '73738584947384'}) r = db.books.insert_one({'title': 'The third book', 'isbn': '73738584947384'})
@ -23,7 +28,7 @@ else:
# book = db.books.find_one({'isbn': '73738584947384'}) # book = db.books.find_one({'isbn': '73738584947384'})
# print(book) # print(book)
# NOTE: In the video we use db.books.update(), migrated to update_one() as update() is deprecated.
db.books.update({'isbn': '181819884728473'}, {'$addToSet': {'favorited_by': 120}}) db.books.update_one({'isbn': '181819884728473'}, {'$addToSet': {'favorited_by': 120}})
book = db.books.find_one({'isbn': '181819884728473'}) book = db.books.find_one({'isbn': '181819884728473'})
print(book) print(book)

Loading…
Cancel
Save