Docs Menu
Docs Home
MongoDB Manual
/ / /


On this page

  • Definition
  • Syntax
  • Example

Sets the 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().setWriteConcern( { w: <value>, j: <boolean>, wtimeout: <number> } )

The fields are:


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.

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

In the following example:

  • Two mongod or mongod instances must acknowledge writes.

  • There is a 1 second timeout to wait for write acknowledgments.

db.getMongo().setWriteConcern( { w: 2, wtimeout: 1000 } )


See also:

← Mongo.startSession()