Database Manual / Reference / mongosh Methods / Connections

Mongo.getWriteConcern() (mongosh method方法)

Definition定义

Mongo.getWriteConcern()
Returns:返回The current 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().getWriteConcern()

This operation returns a document with the following values:此操作返回具有以下值的文档:

{ w: <value>, wtimeout: <number>, j: <boolean> }

The fields are:这些字段是:

Field字段Description描述
w

The number of mongod or mongod instances that must acknowledge a write. Possible values are:必须确认写入的mongodmongod实例的数量。可能的值有:

  • "majority". A majority of the target instances must acknowledge the write.。大多数目标实例必须确认写入。
  • <number>. The specified number of target instances must acknowledge the write.。指定数量的目标实例必须确认写入。
  • <custom write concern name>. A user defined write concern, the tagged instances must acknowledge the write.。用户定义的写入关注,标记的实例必须确认写入。

See write concern specification for details.有关详细信息,请参阅编写入关注规范

jA boolean value. j: true requests acknowledgment that the write operation has been written to the on-disk journal.一个布尔值。j: true请求确认写入操作已写入磁盘日志
wtimeoutThe number of milliseconds to wait for acknowledgment of the write concern. wtimeout is only applicable when w has a value greater than 1.等待写入关注确认的毫秒数。wtimeout仅在w的值大于1时适用。

Example示例

To return the current write concern, enter the following:要返回当前写入关注,请输入以下内容:

db.getMongo().getWriteConcern()

When a write concern is specified using Mongo.setWriteConcern(), the output of Mongo.getWriteConcern() is similar to:当使用Mongo.setWriteConcern()指定写关注时,Mongo.getWriteConcern()的输出类似于:

WriteConcern { w: 2, wtimeout: 1000, j: true }

The Mongo.getWriteConcern() command returns an empty line if no write concern has been specified.如果没有指定写关注,Mongo.getWriteConcern()命令将返回一个空行。