Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set writeConcern level to unacknowledged in pymongo

I have a huge mongodb database and due to the fact that only one thread is writing in a collection at any given time and all the updates are performed on documents that already exist, I'd like mongodb to not acknowledge any operation because I want to boost performance.

I came across a writeConcern rundown here but I have no idea how apply use the unacknowledged write concern on updates in pymongo.

Note: I'm using pymongo 2.7.1, python 3.4 and mongo 2.6.3

Edit: I'd like to add the bulk version of modified write concern update to Neil Lunn's solution.

like image 419
thehousedude Avatar asked Aug 28 '14 06:08

thehousedude


1 Answers

You can do this in either one of two places.

  1. Either when obtaining the initial MongoClient:

    client = MongoClient(w=0)
    
  2. Or when issuing statements as an additional argument:

    result = db.collection.update({ 'a': 1 }, { 'a': 2 }, w=0 )
    

Both are valid places to specify a write concern. What you specify on MongoClient is "global" for the connection and the other statements override where used or otherwise just use the "global".

like image 131
Neil Lunn Avatar answered Oct 04 '22 01:10

Neil Lunn