Docs Menu
Docs Home
/
MongoDB Manual
/ / /

Mongo.getWriteConcern()

On this page

  • Definition
  • Syntax
  • Example
Mongo.getWriteConcern()
Returns:The current write concern for the Mongo() connection object.

See the Write Concern for an introduction to write concerns in MongoDB.

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:

  • "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.

j
A boolean value. j: true requests acknowledgment that the write operation has been written to the on-disk journal.
wtimeout
The number of milliseconds to wait for acknowledgement of the write concern. wtimeout is only applicable when w has a value greater than 1.

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:

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

The Mongo.getWriteConcern() command returns an empty line if no write concern has been specified.

Tip

See also:

Back

Mongo.getReadPrefTagSet()