Mongo.setWriteConcern()
On this page
Definition
Mongo.setWriteConcern()
Sets the write concern for the
Mongo()
connection object.See the Write Concern for an introduction to write concerns in 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 Enterprise: The subscription-based, self-managed version of MongoDB
MongoDB Community: The source-available, free-to-use, and self-managed version of MongoDB
Syntax
The command takes the following form:
db.getMongo().setWriteConcern( { w: <value>, j: <boolean>, wtimeout: <number> } )
The fields are:
Field | Description |
---|---|
| The number of
See write concern specification for details. |
| A boolean value. |
| The number of milliseconds to wait for acknowledgment of the
write concern. |
Example
In the following example:
There is a
1
second timeout to wait for write acknowledgments.
db.getMongo().setWriteConcern( { w: 2, wtimeout: 1000 } )