From 2bfe78fc8f5254498ac7c0e61023ebc6a65834c8 Mon Sep 17 00:00:00 2001 From: Michael Kennedy Date: Sun, 28 Jun 2020 10:05:08 -0700 Subject: [PATCH] Fixes #9 - Some commands are deprecated. --- src/05_pymongo/play_around_pymongo/program.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/05_pymongo/play_around_pymongo/program.py b/src/05_pymongo/play_around_pymongo/program.py index bad61be..6775d45 100644 --- a/src/05_pymongo/play_around_pymongo/program.py +++ b/src/05_pymongo/play_around_pymongo/program.py @@ -5,7 +5,12 @@ client = pymongo.MongoClient(conn_str) 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") # insert some data... r = db.books.insert_one({'title': 'The third book', 'isbn': '73738584947384'}) @@ -23,7 +28,7 @@ else: # book = db.books.find_one({'isbn': '73738584947384'}) # print(book) - -db.books.update({'isbn': '181819884728473'}, {'$addToSet': {'favorited_by': 120}}) +# NOTE: In the video we use db.books.update(), migrated to update_one() as update() is deprecated. +db.books.update_one({'isbn': '181819884728473'}, {'$addToSet': {'favorited_by': 120}}) book = db.books.find_one({'isbn': '181819884728473'}) print(book)