Bri*_*Yeh 3 python mongodb pymongo
我将连接默认为w = 0但是对于collection.update_one或collection.update_many,我想通过设置参数w = 0来设置每个操作的write_concern.相反,我收到此错误:
update_one() got an unexpected keyword argument 'w'
Run Code Online (Sandbox Code Playgroud)
这样做的正确方法是什么?我看到插入接受'w'但不接受update_one或update_many.为什么?
覆盖PyMongo客户端,数据库或集合的写入问题的新方法是使用"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}})
Run Code Online (Sandbox Code Playgroud)
有关写入问题和with_options,请参阅文档
| 归档时间: |
|
| 查看次数: |
654 次 |
| 最近记录: |