Write Concern for Replica Sets (page 586) Write concern is the guarantee an application requires from MongoDB to consider a write operation successful. Read Preference (page 588) Applications specify read preference to control how drivers direct read operations to members of the replica set. Read Preference Processes (page 591) With replica sets, read operations may have additional semantics and behav- ior. Write Concern for Replica Sets Verify Write Operations to Replica Sets Modify Default Write Concern From the perspective of a client application, whether a MongoDB instance is running as a single server (i.e. “stan- dalone”) or a replica set is transparent. However, replica sets offer some configuration options for write. 12 For a replica set, the default write concern (page 78) confirms write operations only on the primary. You can, how- ever, override this default write concern, such as to confirm write operations on a specified number of the replica set members. To override the default write concern, specify a write concern with each write operation. For example, the following method includes a write concern that specifies that the method return only after the write propagates to the primary and at least one secondary or the method times out after 5 seconds. You can include a timeout threshold for a write concern. This prevents write operations from blocking indefinitely if the write concern is unachievable. For example, if the write concern requires acknowledgement from 4 members of the replica set and the replica set has only available 3 members, the operation blocks until those members become available. See wtimeout (page 131). See also: Write Method Acknowledgements (page 857) You can modify the default write concern for a replica set by setting the getLastErrorDefaults setting in the replica set configuration (page 652). The following sequence of commands creates a configuration that waits for the write operation to complete on a majority of the voting members before returning: If you issue a write operation with a specific write concern, the write operation uses its own write concern instead of the default. Note: Use of insufficient write concern can lead to rollbacks (page 584) in the case of replica set failover (page 580). 586 Chapter 9. Replication cfg = rs.conf() cfg.settings = {} cfg.settings.getLastErrorDefaults = { w: "majority", wtimeout: 5000 } rs.reconfig(cfg) db.products.insert( { item: "envelopes", qty : 100, type: "Clasp" }, { writeConcern: { w: 2, wtimeout: 5000 } } ) MongoDB Documentation, Release 3.0.4 12 Sharded clusters where the shards are also replica sets provide the same configuration options with regards to write and read operations.