File tree 1 file changed +9
-5
lines changed
src/05_pymongo/play_around_pymongo
1 file changed +9
-5
lines changed Original file line number Diff line number Diff line change 5
5
6
6
db = client .the_small_bookstore
7
7
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
11
10
# for details
12
-
13
- if db .books .estimated_document_count () == 0 :
11
+ if db .books .count_documents ({}) == 0 :
14
12
print ("Inserting data" )
15
13
# insert some data...
16
14
r = db .books .insert_one ({'title' : 'The third book' , 'isbn' : '73738584947384' })
24
22
# # print(book, type(book))
25
23
# # book['favorited_by'] = []
26
24
# book['favorited_by'].append(100)
25
+
26
+ # Updated from recording, was:
27
27
# 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
+
28
32
# book = db.books.find_one({'isbn': '73738584947384'})
29
33
# print(book)
30
34
You can’t perform that action at this time.
0 commit comments