Definition定义
Mongo.setWriteConcern()Sets the write concern for the设置Mongo()connection object.Mongo()连接对象的写入关注。See the Write Concern for an introduction to write concerns in MongoDB.有关在MongoDB中编写关注的介绍,请参阅写入关注。
Compatibility兼容性
This method is available in deployments hosted in the following environments:此方法在以下环境中托管的部署中可用:
- MongoDB Atlas
: The fully managed service for MongoDB deployments in the cloud:云中MongoDB部署的完全托管服务
- MongoDB Enterprise
: The subscription-based, self-managed version of MongoDB:MongoDB的基于订阅的自我管理版本 - MongoDB Community
: The source-available, free-to-use, and self-managed version of MongoDB:MongoDB的源代码可用、免费使用和自我管理版本
Syntax语法
The command takes the following form:该命令采用以下形式:
db.getMongo().setWriteConcern( { w: <value>, j: <boolean>, wtimeout: <number> } )
The fields are:这些字段是:
w |
|
j | j: true requests acknowledgment that the write operation has been written to the on-disk journal.j:true请求确认写入操作已写入磁盘日志。 |
wtimeout | wtimeout is only applicable when w has a value greater than 1.wtimeout仅在w的值大于1时适用。 |
Example示例
In the following example:在以下示例中:
Two两个mongodormongodinstances must acknowledge writes.mongod或mongod实例必须确认写入。There is a等待写入确认有1second timeout to wait for write acknowledgments.1秒的超时时间。
db.getMongo().setWriteConcern( { w: 2, wtimeout: 1000 } )