How to initialize a UnorderedBulkOp ()?

New to MongoDB , I'm trying to optimize bulk writing to a database. However, I do not understand how to initialize Bulk() operations.

I understand that since the insertions will be performed in the collection, this is where (or rather "what") the initializeUnorderedBulkOp() should be initialized:

The code below describes all the cases that I can think of:

 import pymongo conn = pymongo.MongoClient('mongodb.example.com', 27017) db = conn.test coll = db.testing # tried all of the following # this one does not make much sense to me as I insert to a collection, added for completeness bulk = db.initializeUnorderedBulkOp() # that one seems to be the most reasonable to me bulk = coll.initializeUnorderedBulkOp() # that one is from http://blog.mongodb.org/post/84922794768/mongodbs-new-bulk-api bulk = db.collection('testing').initializeUnorderedBulkOp() # the staging and execution # bulk.find({'name': 'hello'}).update({'name': 'hello', 'who': 'world'}) # bulk.execute() 

The exception is

 TypeError: 'Collection' object is not callable. If you meant to call the 'initializeUnorderedBulkOp' method on a 'Database' object it is failing because no such method exists. 

with 'Database' for the first case and 'Collection' for the last two

How to use initializeUnorderedBulkOp() ?

+5
source share
1 answer

In Python (using the pymongo module), the method name is not initializeUnorderedBulkOp , but initialize_unordered_bulk_op .

You should call it, as you correctly understood, in the collection (in your case coll.initialize_unordered_bulk_op() should work).

+9
source

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


All Articles