I have the connection defaulted to w=0 but for collection.update_one or collection.update_many, I want to set the write_concern per operation by setting the parameter w=0. Instead I'm getting this error:
update_one() got an unexpected keyword argument 'w'
What is the right way to do this? I saw that insert accepts 'w' but not update_one or update_many. Why?
The new way to override a PyMongo client's, database's, or collection's write concern is using "with_options":
client = MongoClient(w=0)
collection = client.database.collection
w1_collection = collection.with_options(write_concern=WriteConcern(w=1))
w1_collection.update_one({'_id': 1}, {'$inc': {'x': 3}})
See the docs for write concern and with_options
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With