Error
Error Code: 148

MongoDB Error 148: Majority Read Concern Disabled

📦 MongoDB
📋

Description

This error indicates that the MongoDB replica set is not configured to support `readConcern: "majority"`. It typically occurs when a client attempts to use this read concern, but the underlying replica set configuration or storage engine prevents it, impacting data consistency guarantees.
💬

Error Message

Read Concern Majority Not Enabled
🔍

Known Causes

4 known causes
⚠️
Read Concern Majority Disabled
The replica set configuration (`replSetGetConfig`) has `readConcernMajority` explicitly set to `false`.
⚠️
Incompatible Storage Engine
The replica set members are using a storage engine (e.g., MMAPv1) that does not support `readConcern: "majority"`.
⚠️
Old Feature Compatibility Version
The replica set's `featureCompatibilityVersion` is set to an older MongoDB version that predates `readConcern: "majority"` support.
⚠️
Unhealthy Replica Set State
The replica set is not fully initialized, lacks a primary, or has an insufficient number of healthy members to form a majority.
🛠️

Solutions

3 solutions available

1. Enable Majority Read Concern for Existing Replica Set medium

Modify the replica set configuration to enable majority read concern.

1
Connect to your MongoDB replica set using the mongo shell or mongosh.
mongosh mongodb://your_replica_set_host:27017
2
Access the admin database.
use admin
3
Initiate a configuration update to enable majority read concern. This requires updating the `settings.readConcern.default` parameter. You might need to fetch the current configuration first to avoid overwriting other settings.
var cfg = rs.conf();
cfg.settings.readConcern.default = "majority";
rs.reconfig(cfg);
4
Verify the configuration change by checking the replica set status.
rs.status()

2. Configure Majority Read Concern During New Replica Set Initialization medium

Set majority read concern when creating a new replica set.

1
When starting your MongoDB instances for a new replica set, use the `--replSet` option and configure the `settings.readConcern.default` parameter in the `mongod.conf` file.
# Example mongod.conf snippet
replication:
  replSetName: myReplicaSetName
settings:
  readConcern:
    default: "majority"
2
Start the mongod processes with the specified configuration file.
mongod --config /path/to/your/mongod.conf
3
Connect to one of the mongod instances and initialize the replica set.
mongosh mongodb://your_primary_host:27017
4
Initialize the replica set. The configuration defined in the `mongod.conf` will be applied.
rs.initiate()

3. Temporarily Use a Less Strict Read Concern easy

For non-critical reads, switch to a read concern that doesn't require majority confirmation.

1
When executing read operations, specify a read concern other than 'majority'. Common alternatives include 'local' or 'available'. This is done at the application level or within the mongo shell.
db.collection.find().readConcern("local")
2
For application code, check your MongoDB driver's documentation for how to set read concerns per operation or per client session.
// Example in Node.js driver
const client = new MongoClient(uri, { readConcern: { level: 'local' } });
🔗

Related Errors

5 related errors