Pymongo bulk liners do not work

I am following the http://api.mongodb.org/python/current/tutorial.html tutorial for bulk insertions. However, I am getting the error message below. What am I missing? Review_array is json_array

client = MongoClient() client = MongoClient('localhost', 27017) db = client.is_proj db_handle = db.reviews self.db_handle.insert_many(reviews_array) 

Error:

 TypeError: 'Collection' object is not callable. If you meant to call the 'insert_many' method on a 'Collection' object it is failing because no such method exists. 
+5
source share
1 answer

In pymongo, prior to V3.0 , you use insert for both single-document and bulk inserts. If you pass in a document, it performs a single insert, and if you pass in another iterative (list, generator), it performs bulk insert.

insert_many() did not exist in pimongo before V3.0.

In pymongo V3.0, they introduced insert_many and insert_one , and the use of plain insert is deprecated.

+8
source

Source: https://habr.com/ru/post/1215324/


All Articles