Search code examples
pythonmongodbtimeoutpymongo

How to set the maxTimeMS for a bulk_write operation?


I get a lot of pymongo.errors.ExecutionTimeout when using bulk_write with a list of updates. I can't find the timeout duration nor how to change it.

collection.bulk_write(operationslist, ordered = False, maxTimeMS = 0) doesn't work (unexpected keyword)

How can i set it? Or a parameter on collection (or connection) level, to avoid timeouts?


Solution

  • In the docs, bulkWrite sets the timeout via the writeConcern property, e.g.

     db.test.bulkWrite(
          [
             { updateMany :
                ... 
    
             },
             ...
          ],
          { writeConcern : { w : "majority", wtimeout : 100 } }
       );
    

    so I imagine the pymongo driver will be similar. I'm not a Python dev but maybe:

    coll = db.get_collection('test', write_concern=WriteConcern(w=3, wtimeout=1, wtimeout=1000))
    coll.bulk_write(...)