How to set up Write Concern on a server?

settings.getLastErrorDefaults
A document that specifies the write concern for the replica set.
The replica set will use this write concern only when write operations or getLastError specify no other write concern.

Does the “settings.getLastErrorDefaults” setting change the Write Conern option by default for all write queries for mongodb server?

And what is the value that has changed like this, and if the Write Conern applied to the query comes in? Are you saying that if the w option exists in operation, you ignore the setting value of settings.getLastErrorDefaults?

Hello @Kim_Hakseon, here is the explanation:

Does the “settings.getLastErrorDefaults” setting change the Write Concern option by default for all write queries for mongodb server?

“settings.getLastErrorDefaults” is an optional document specified in the replica set configuration - rsconf. It specifies the default write concern for the replica set.

But, you can override this default setting for example, for a specific write operation:

db.collection.insertOne(
  { someField: "some value" }, 
  { writeConcern: { w : "majority", wtimeout : 100 } } 
)

And what is the value that has changed like this, and if the Write Concern applied to the query comes in? Are you saying that if the w option exists in operation, you ignore the setting value of settings.getLastErrorDefaults?

Yes. The write concern specified for a write operation like db.collection.updateOne( { //… }, { //… }, { // write concern…} ), overrides the default setting specified in the “settings.getLastErrorDefaults” of the replica set configuration.

1 Like

So if you want to use full sync in a three-node replica set (P-S-S) structure, can I give you w:3?

The write concern for a replica set describes the number of data-bearing members (i.e. the primary and secondaries, but not arbiters) that must acknowledge a write operation before the operation returns as successful.

In a replica set, data gets in sync on all nodes. The write concern specifies that an acknowledgement is received after the data is written to 1, n (2 or 3 in your case) or 'majority' of the nodes. So, whatever the value you specify, the data is always syncd on all data bearing nodes. The write concern determines the acknowledgement level only.

See the write concern’s ‘w’ option for more details.

1 Like

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.