diff --git a/jstests/core/read_majority_mmap.js b/jstests/core/read_majority_mmap.js new file mode 100644 index 00000000000..367908eea42 --- /dev/null +++ b/jstests/core/read_majority_mmap.js @@ -0,0 +1,12 @@ +// Ensure read majority works on a standalone node, even with non-snapshotting storage engines. + +(function() { +"use strict"; + +var name = "readMajority"; +db = db.getSiblingDB(name); +assert.writeOK(db.foo.insert({x: 3})); + +assert.commandWorked(db.foo.runCommand({find: name, readConcern: {level: "majority"}})); + +}()); diff --git a/src/mongo/db/dbcommands.cpp b/src/mongo/db/dbcommands.cpp index 9fcfb6032e1..2b0e7a161a4 100644 --- a/src/mongo/db/dbcommands.cpp +++ b/src/mongo/db/dbcommands.cpp @@ -1320,7 +1320,11 @@ bool Command::run(OperationContext* txn, return false; } } - if (readConcern.getLevel() == repl::ReadConcernLevel::kMajorityReadConcern) { + + if ((replCoord->getReplicationMode() == + repl::ReplicationCoordinator::Mode::modeReplSet || + testingSnapshotBehaviorInIsolation) && + readConcern.getLevel() == repl::ReadConcernLevel::kMajorityReadConcern) { Status status = txn->recoveryUnit()->setReadFromMajorityCommittedSnapshot(); if (!status.isOK()) { replyBuilder->setMetadata(rpc::makeEmptyMetadata()).setCommandReply(status);