October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsPC HealthRecommendedCrashes, freezes, slowdowns? Check your PC nowSpot repairable issues before they interrupt work.Check PCOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk4 min

How to Set MongoDB Write Concern Defaults—and What Journaling Controls

Use setDefaultRWConcern to set a MongoDB cluster-wide write concern. Learn how the implicit majority default, arbiter exception, journaling, and application overrides affect acknowledgments.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Set a cluster-wide MongoDB write concern with setDefaultRWConcern, then verify it with getDefaultRWConcern. Journaling is a separate durability behavior: on current MongoDB releases, you generally do not enable or disable journaling with a configuration switch. The usual implicit write concern is w: "majority", but an arbiter topology can make it { w: 1 }.

What MongoDB uses by default

MongoDB’s implicit default write concern is generally w: "majority", meaning the write waits for acknowledgment from a calculated majority of voting members. There is an important exception: if the replica set has at least one arbiter and the number of non-arbiter voting members is not greater than the voting majority, the implicit value is { w: 1 }. MongoDB’s defaults reference illustrates the exception with two non-arbiters plus one arbiter; four non-arbiters plus one arbiter yields { w: "majority" }. See MongoDB’s default read and write concern reference.

As an Amazon Associate I earn from qualifying purchases.

That implicit value is not necessarily the value your application uses. A configured global default applies only to operations that do not specify their own write concern. Drivers can set concerns at client, database, collection, or operation scope, with more specific scopes taking precedence. For a transaction, the transaction-level write concern controls commit; operation-, collection-, and database-level concerns do not apply. See MongoDB’s write concern documentation.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Set a cluster-wide write concern

Run setDefaultRWConcern on the primary for a replica set, or through mongos for a sharded cluster. In a sharded deployment, the global default is stored through the config server replica set; it is not a setting to configure separately on every shard.

  1. Connect to the right endpoint. Use the replica-set primary, or connect to mongos for a sharded cluster.
  2. Set the default. For example, this sets majority acknowledgment as the default and asks the command itself to wait for majority acknowledgment:
    db.adminCommand({
      setDefaultRWConcern: 1,
      defaultWriteConcern: { w: "majority" },
      writeConcern: { w: "majority" }
    })
  3. Check version compatibility. The command requires feature compatibility version (FCV) 4.4 or later. Starting in MongoDB 5.0, after a cluster-wide write concern is set, the command cannot unset it. Review the consequences before applying a cluster-wide value. See the setDefaultRWConcern command reference.

defaultWriteConcern must include a w field and cannot use w: 0. If you omit wtimeout, its value is 0, so the operation can wait indefinitely for the requested acknowledgment level. If you choose a timeout, set it for the deployment’s replication and availability needs: a timeout means the requested acknowledgment was not reached within the limit, not that MongoDB undid work already performed on the primary.

Verify the stored default

Run this administrative command against the deployment endpoint:

db.adminCommand({ getDefaultRWConcern: 1 })

Inspect defaultWriteConcern and defaultWriteConcernSource. A source of implicit means MongoDB supplied the implicit value; global means a cluster-wide default was configured. After an update, secondaries and individual mongos instances may briefly return or use cached values. Allow time for propagation and query the endpoint whose behavior you are checking. See the getDefaultRWConcern command reference and the global-default command documentation.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Understand the difference between w and j

w specifies how many replica-set members must acknowledge a write; j specifies whether eligible acknowledgments wait for journal persistence rather than just in-memory application. They answer different questions and are not interchangeable. MongoDB documents the options in its write concern reference.

Setting What acknowledgment means Durability and trade-off
{ w: 1 } The primary acknowledges the write. With numeric w and no j specified, acknowledgment can follow in-memory application rather than journal persistence.
{ w: "majority" } A calculated majority of voting members acknowledges the write. When j is omitted, writeConcernMajorityJournalDefault controls journal waiting; it defaults to true.
{ w: 1, j: true } The primary acknowledges after journal persistence. Requests journal persistence on the primary, but does not by itself require acknowledgment from other members.

For majority writes with j omitted, writeConcernMajorityJournalDefault: true requires journal persistence, equivalent to j: true. If that setting is false, a majority write can be acknowledged after in-memory application instead. MongoDB warns that this can expose acknowledged writes to rollback after a transient loss of a majority of nodes, such as a crash and restart. See MongoDB’s write concern reference and the writeConcernMajorityJournalDefault parameter reference.

Majority acknowledgment can take longer or fail to complete while enough members are unavailable. Topology matters: if the number of data-bearing voting members is only the calculated majority, losing one may leave the set unable to satisfy a majority write. A configured wtimeout reports that the requested acknowledgment was not achieved in time; it does not reverse the primary’s modification.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Do not use the removed journal on/off options

Journaling helps MongoDB recover writes recorded in the journal but not yet reflected in data files after an unexpected process exit. MongoDB removed storage.journal.enabled and the --journal / --nojournal command-line options starting in MongoDB 6.1. Do not use those obsolete controls when configuring a current release. See the journal configuration reference.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

If you need to adjust journal timing, storage.journal.commitIntervalMs is the journal commit interval setting for mongod. It is distinct from storage.syncPeriodSecs, which is not a journaling control. See the commitIntervalMs option and the syncPeriodSecs option.

Before changing the default

  • Confirm the MongoDB version and FCV support the command.
  • Count voting and data-bearing members, including any arbiters, to understand the implicit default and majority availability.
  • Check client, database, collection, operation, and transaction settings for explicit concerns that override the global default.
  • Choose whether your priority is primary-only acknowledgment, majority acknowledgment, or explicit journal persistence, and account for the latency and availability consequences.
  • If setting a timeout, remember that a write concern timeout does not roll back a write already made on the primary.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Crashes, No Sound, or Screen Glitches?Free driver scan
Windows Errors? Fix Them Before They SpreadFree repair scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.