Error
Error Code: 100

MongoDB Error 100: Write Concern Not Met

📦 MongoDB
📋

Description

MongoDB Error 100, "Unsatisfiable Write Concern," indicates that a write operation failed to meet the specified writeConcern level. This means the database could not achieve the required number of acknowledgments from replica set members or satisfy journaling requirements before timing out. It often points to issues with replica set health or network connectivity.
💬

Error Message

Unsatisfiable Write Concern
🔍

Known Causes

4 known causes
⚠️
Unhealthy Replica Set
Not enough replica set members are available, reachable, or in a primary/secondary state to satisfy the 'w' (number of nodes) or 'j' (journaling) components of the write concern.
⚠️
Network Connectivity Issues
Network problems prevent the primary node from communicating with the required number of secondary nodes or the majority of the replica set, making acknowledgments impossible.
⚠️
Overly Strict Write Concern
The write concern is configured for a level of durability or acknowledgment (e.g., w: "majority" on a small or struggling replica set) that is difficult to achieve under current cluster conditions.
⚠️
Acknowledgment Timeout
The 'wtimeout' parameter for the write concern is too low, causing the operation to time out before the necessary acknowledgments can be received, even if they would eventually arrive.
🛠️

Solutions

4 solutions available

1. Temporarily Loosen Write Concern easy

Reduce the write concern level for operations to allow writes to proceed even if not all replicas acknowledge them immediately.

1
When performing write operations, explicitly set the `w` option to a lower value. For example, `w: 1` means only the primary needs to acknowledge the write. `w: 'majority'` is the default and often the cause of this error in a replica set.
db.collection.insertOne({ item: 'book' }, { w: 1 })
2
Alternatively, if you are using a driver, consult its documentation for how to set the write concern for individual operations. For example, in PyMongo:
collection.insert_one({'item': 'book'}, w=1)
3
This is a quick fix for immediate availability but should be used cautiously as it sacrifices durability guarantees. Revert to a higher write concern (e.g., `w: 'majority'`) once the underlying issue is resolved.

2. Investigate Replica Set Health and Network Connectivity medium

Ensure all members of the replica set are healthy, reachable, and have stable network connections.

1
Connect to your MongoDB primary and run the `rs.status()` command to check the health of your replica set.
rs.status()
2
Examine the output for any members that are `DOWN`, `STARTUP`, `UNHEALTHY`, or have significant replication lag. Pay close attention to the `stateStr` for each member.
3
Verify network connectivity between all replica set members. Ensure there are no firewall rules blocking communication on the MongoDB port (default 27017).
ping <replica_set_member_ip>
4
Check for any recent network disruptions, high latency, or packet loss between the nodes. Address any network issues identified.

3. Increase Replica Set Size or Add More Members medium

If your replica set is small (e.g., 3 members) and one member is frequently unavailable, consider adding more members to increase fault tolerance.

1
Provision new MongoDB instances that meet your requirements.
2
Configure these new instances to join your existing replica set by setting the `replication.replSetName` in their configuration files and starting them with the `--replSet` option.
mongod --replSet myReplicaSet --dbpath /data/rs1 --port 27017 --bind_ip localhost,<your_ip>
3
Connect to the primary node of your existing replica set and add the new member using the `rs.add()` command.
rs.add("newNodeHost:27017")
4
Monitor the replica set status (`rs.status()`) to ensure the new member is syncing and becomes a healthy member of the replica set.
rs.status()

4. Optimize Write Operations and Application Logic advanced

Review application code for inefficient write patterns or excessive load that might be overwhelming the replica set.

1
Analyze application logs and MongoDB slow query logs to identify write operations that are taking a long time to complete.
db.setProfilingLevel(1, 1000) // Enable profiling for queries slower than 1000ms
2
Look for patterns of very large or frequent writes that could be causing contention or overwhelming the oplog. Consider batching writes where appropriate.
3
Ensure that indexes are properly configured to support your write operations. Missing or inefficient indexes can significantly slow down writes.
db.collection.createIndex({ field: 1 })
4
If the application is performing many individual writes instead of bulk operations, refactor the application to use `insertMany`, `updateMany`, or `deleteMany` where possible.
db.collection.insertMany([{ item: 'apple' }, { item: 'banana' }])
🔗

Related Errors

5 related errors