diff options
-rw-r--r-- | jstests/noPassthroughWithMongod/default_read_pref.js | 28 | ||||
-rw-r--r-- | src/mongo/shell/db.js | 7 |
2 files changed, 33 insertions, 2 deletions
diff --git a/jstests/noPassthroughWithMongod/default_read_pref.js b/jstests/noPassthroughWithMongod/default_read_pref.js new file mode 100644 index 00000000000..05be7915626 --- /dev/null +++ b/jstests/noPassthroughWithMongod/default_read_pref.js @@ -0,0 +1,28 @@ +// Tests that the default read preference is 'unset', and that the slaveOk bit is not set +// on read commands run with an 'unset' read preference. +(function() { + + "use strict"; + + var mongo = db.getMongo(); + try { + var commandsRan = []; + db._mongo = { + getSlaveOk: function() { return false; }, + getReadPrefMode: function() { return mongo.getReadPrefMode(); }, + getReadPref: function() { return mongo.getReadPref(); }, + runCommand: function(db, cmd, opts) { + commandsRan.push({db: db, cmd: cmd, opts:opts}); + } + }; + + db.runReadCommand({ping: 1}); + assert.eq(commandsRan.length, 1); + assert.docEq(commandsRan[0].cmd, {ping: 1}, "The command should not have been wrapped."); + assert.eq(commandsRan[0].opts & DBQuery.Option.slaveOk, 0, "The slaveOk bit should not be set."); + + } finally { + db._mongo = mongo; + } + +})(); diff --git a/src/mongo/shell/db.js b/src/mongo/shell/db.js index 9be0f76b72d..b20224c5869 100644 --- a/src/mongo/shell/db.js +++ b/src/mongo/shell/db.js @@ -97,8 +97,11 @@ DB.prototype.commandHelp = function( name ){ this.getMongo().getReadPref()); var options = 0; - // We automatically set slaveOk if readPreference is anything but primary. - if (this.getMongo().getReadPrefMode() !== "primary") { + var readPrefMode = this.getMongo().getReadPrefMode(); + + // Set slaveOk if readPrefMode has been explicitly set with a readPreference other than + // primary. + if (!!readPrefMode && readPrefMode !== "primary") { options |= 4; } |