summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Storch <david.storch@10gen.com>2015-09-28 09:51:50 -0400
committerDavid Storch <david.storch@10gen.com>2015-09-30 13:25:15 -0400
commitdf2a33f9974950ebe484edfa29171cec53071b0a (patch)
treea257aa80208cece12cecee6c4cff9dbc3ec0993f
parent17a3bd06f4bdb3b7d761ea059b996004a8b6ae7f (diff)
downloadmongo-df2a33f9974950ebe484edfa29171cec53071b0a.tar.gz
SERVER-20067 SERVER-19572 set readMode in shell based on wire version
"compatibility" readMode now causes the shell to detect whether or not to use find/getMore commands based on wire version. "commands" mode forces use of the find/getMore commands, and "legacy" mode forces uses of legacy OP_QUERY/OP_GET_MORE reads. Also configures tests to force use of "commands" or "legacy" mode as appropriate.
-rw-r--r--buildscripts/resmokeconfig/suites/aggregation.yml4
-rw-r--r--buildscripts/resmokeconfig/suites/aggregation_auth.yml1
-rw-r--r--buildscripts/resmokeconfig/suites/audit.yml1
-rw-r--r--buildscripts/resmokeconfig/suites/bulk_gle_passthrough.yml1
-rw-r--r--buildscripts/resmokeconfig/suites/concurrency_sharded.yml1
-rw-r--r--buildscripts/resmokeconfig/suites/decimal.yml3
-rw-r--r--buildscripts/resmokeconfig/suites/ese.yml1
-rw-r--r--buildscripts/resmokeconfig/suites/failpoints.yml1
-rw-r--r--buildscripts/resmokeconfig/suites/failpoints_auth.yml1
-rw-r--r--buildscripts/resmokeconfig/suites/gle_auth.yml1
-rw-r--r--buildscripts/resmokeconfig/suites/gle_auth_basics_passthrough.yml1
-rw-r--r--buildscripts/resmokeconfig/suites/jstestfuzz.yml3
-rw-r--r--buildscripts/resmokeconfig/suites/multiversion.yml1
-rw-r--r--buildscripts/resmokeconfig/suites/no_passthrough_with_mongod.yml3
-rw-r--r--buildscripts/resmokeconfig/suites/no_server.yml1
-rw-r--r--buildscripts/resmokeconfig/suites/rlp.yml3
-rw-r--r--buildscripts/resmokeconfig/suites/sasl.yml1
-rw-r--r--buildscripts/resmokeconfig/suites/sharding.yml1
-rw-r--r--buildscripts/resmokeconfig/suites/sharding_auth.yml1
-rw-r--r--buildscripts/resmokeconfig/suites/sharding_ese.yml1
-rw-r--r--buildscripts/resmokeconfig/suites/sharding_gle_auth_basics_passthrough.yml1
-rw-r--r--buildscripts/resmokeconfig/suites/sharding_legacy.yml1
-rw-r--r--buildscripts/resmokeconfig/suites/snmp.yml1
-rw-r--r--buildscripts/resmokeconfig/suites/ssl.yml1
-rw-r--r--buildscripts/resmokeconfig/suites/ssl_special.yml1
-rw-r--r--buildscripts/resmokeconfig/suites/tool.yml1
-rw-r--r--buildscripts/resmokeconfig/suites/with_server.yml3
-rw-r--r--buildscripts/resmokelib/parser.py2
-rw-r--r--etc/evergreen.yml20
-rw-r--r--jstests/core/pseudocommand_db.js2
-rw-r--r--jstests/core/type4.js8
-rw-r--r--jstests/core/validate_pseudocommand_ns.js2
-rw-r--r--src/mongo/shell/mongo.js54
-rw-r--r--src/mongo/shell/shell_options.cpp13
-rw-r--r--src/mongo/shell/utils.js2
35 files changed, 108 insertions, 35 deletions
diff --git a/buildscripts/resmokeconfig/suites/aggregation.yml b/buildscripts/resmokeconfig/suites/aggregation.yml
index 6bef7c88600..7db3497afb8 100644
--- a/buildscripts/resmokeconfig/suites/aggregation.yml
+++ b/buildscripts/resmokeconfig/suites/aggregation.yml
@@ -7,7 +7,9 @@ selector:
executor:
js_test:
- config: {}
+ config:
+ shell_options:
+ readMode: commands
hooks:
- class: CleanEveryN
n: 20
diff --git a/buildscripts/resmokeconfig/suites/aggregation_auth.yml b/buildscripts/resmokeconfig/suites/aggregation_auth.yml
index 5b978cb342c..7c0a83d9a97 100644
--- a/buildscripts/resmokeconfig/suites/aggregation_auth.yml
+++ b/buildscripts/resmokeconfig/suites/aggregation_auth.yml
@@ -28,6 +28,7 @@ executor:
authenticationMechanism: SCRAM-SHA-1
password: *keyFileData
username: __system
+ readMode: commands
hooks:
- class: CleanEveryN
n: 20
diff --git a/buildscripts/resmokeconfig/suites/audit.yml b/buildscripts/resmokeconfig/suites/audit.yml
index 8df96559d01..ba62241e73b 100644
--- a/buildscripts/resmokeconfig/suites/audit.yml
+++ b/buildscripts/resmokeconfig/suites/audit.yml
@@ -9,3 +9,4 @@ executor:
config:
shell_options:
nodb: ''
+ readMode: commands
diff --git a/buildscripts/resmokeconfig/suites/bulk_gle_passthrough.yml b/buildscripts/resmokeconfig/suites/bulk_gle_passthrough.yml
index 532ee970a2e..edd865044f6 100644
--- a/buildscripts/resmokeconfig/suites/bulk_gle_passthrough.yml
+++ b/buildscripts/resmokeconfig/suites/bulk_gle_passthrough.yml
@@ -9,6 +9,7 @@ executor:
js_test:
config:
shell_options:
+ readMode: legacy
writeMode: legacy
hooks:
- class: CleanEveryN
diff --git a/buildscripts/resmokeconfig/suites/concurrency_sharded.yml b/buildscripts/resmokeconfig/suites/concurrency_sharded.yml
index 132aba312c5..b5bd8b7169e 100644
--- a/buildscripts/resmokeconfig/suites/concurrency_sharded.yml
+++ b/buildscripts/resmokeconfig/suites/concurrency_sharded.yml
@@ -9,3 +9,4 @@ executor:
config:
shell_options:
nodb: ''
+ readMode: commands
diff --git a/buildscripts/resmokeconfig/suites/decimal.yml b/buildscripts/resmokeconfig/suites/decimal.yml
index 3992d1568e2..b97447ebe13 100644
--- a/buildscripts/resmokeconfig/suites/decimal.yml
+++ b/buildscripts/resmokeconfig/suites/decimal.yml
@@ -5,6 +5,9 @@ selector:
executor:
js_test:
+ config:
+ shell_options:
+ readMode: commands
hooks:
- class: CleanEveryN
n: 20
diff --git a/buildscripts/resmokeconfig/suites/ese.yml b/buildscripts/resmokeconfig/suites/ese.yml
index 965bff860a8..60b25db5509 100644
--- a/buildscripts/resmokeconfig/suites/ese.yml
+++ b/buildscripts/resmokeconfig/suites/ese.yml
@@ -9,3 +9,4 @@ executor:
config:
shell_options:
nodb: ''
+ readMode: commands
diff --git a/buildscripts/resmokeconfig/suites/failpoints.yml b/buildscripts/resmokeconfig/suites/failpoints.yml
index 3d7c2c0f24f..5943ce0f49e 100644
--- a/buildscripts/resmokeconfig/suites/failpoints.yml
+++ b/buildscripts/resmokeconfig/suites/failpoints.yml
@@ -9,3 +9,4 @@ executor:
config:
shell_options:
nodb: ''
+ readMode: commands
diff --git a/buildscripts/resmokeconfig/suites/failpoints_auth.yml b/buildscripts/resmokeconfig/suites/failpoints_auth.yml
index 6b23bb2c96b..04c514080be 100644
--- a/buildscripts/resmokeconfig/suites/failpoints_auth.yml
+++ b/buildscripts/resmokeconfig/suites/failpoints_auth.yml
@@ -23,3 +23,4 @@ executor:
keyFile: *keyFile
keyFileData: *keyFileData
nodb: ''
+ readMode: commands
diff --git a/buildscripts/resmokeconfig/suites/gle_auth.yml b/buildscripts/resmokeconfig/suites/gle_auth.yml
index 00c1f2e8226..2f2ec4e97af 100644
--- a/buildscripts/resmokeconfig/suites/gle_auth.yml
+++ b/buildscripts/resmokeconfig/suites/gle_auth.yml
@@ -29,6 +29,7 @@ executor:
authenticationMechanism: SCRAM-SHA-1
password: *keyFileData
username: __system
+ readMode: commands
hooks:
- class: CleanEveryN
n: 20
diff --git a/buildscripts/resmokeconfig/suites/gle_auth_basics_passthrough.yml b/buildscripts/resmokeconfig/suites/gle_auth_basics_passthrough.yml
index 7f40eb75d1f..ebbd50f5f0c 100644
--- a/buildscripts/resmokeconfig/suites/gle_auth_basics_passthrough.yml
+++ b/buildscripts/resmokeconfig/suites/gle_auth_basics_passthrough.yml
@@ -23,6 +23,7 @@ executor:
authenticationMechanism: SCRAM-SHA-1
password: *keyFileData
username: __system
+ readMode: commands
fixture:
class: MongoDFixture
mongod_options:
diff --git a/buildscripts/resmokeconfig/suites/jstestfuzz.yml b/buildscripts/resmokeconfig/suites/jstestfuzz.yml
index c58774c3160..8b9d6774cbf 100644
--- a/buildscripts/resmokeconfig/suites/jstestfuzz.yml
+++ b/buildscripts/resmokeconfig/suites/jstestfuzz.yml
@@ -5,6 +5,9 @@ selector:
executor:
js_test:
+ config:
+ shell_options:
+ readMode: commands
fixture:
class: MongoDFixture
mongod_options:
diff --git a/buildscripts/resmokeconfig/suites/multiversion.yml b/buildscripts/resmokeconfig/suites/multiversion.yml
index 131ef0b758b..6077bd9a037 100644
--- a/buildscripts/resmokeconfig/suites/multiversion.yml
+++ b/buildscripts/resmokeconfig/suites/multiversion.yml
@@ -9,4 +9,5 @@ executor:
config:
shell_options:
nodb: ''
+ readMode: legacy
writeMode: legacy
diff --git a/buildscripts/resmokeconfig/suites/no_passthrough_with_mongod.yml b/buildscripts/resmokeconfig/suites/no_passthrough_with_mongod.yml
index e9c9069545e..c6b6ebcfe84 100644
--- a/buildscripts/resmokeconfig/suites/no_passthrough_with_mongod.yml
+++ b/buildscripts/resmokeconfig/suites/no_passthrough_with_mongod.yml
@@ -13,6 +13,9 @@ selector:
executor:
js_test:
+ config:
+ shell_options:
+ readMode: commands
hooks:
- class: CleanEveryN
n: 20
diff --git a/buildscripts/resmokeconfig/suites/no_server.yml b/buildscripts/resmokeconfig/suites/no_server.yml
index 95a8b6a4c0f..1a2d5edec99 100644
--- a/buildscripts/resmokeconfig/suites/no_server.yml
+++ b/buildscripts/resmokeconfig/suites/no_server.yml
@@ -3,3 +3,4 @@ executor:
config:
shell_options:
nodb: ''
+ readMode: commands
diff --git a/buildscripts/resmokeconfig/suites/rlp.yml b/buildscripts/resmokeconfig/suites/rlp.yml
index feb3aaded27..917da161490 100644
--- a/buildscripts/resmokeconfig/suites/rlp.yml
+++ b/buildscripts/resmokeconfig/suites/rlp.yml
@@ -5,6 +5,9 @@ selector:
executor:
js_test:
+ config:
+ shell_options:
+ readMode: commands
hooks:
- class: CleanEveryN
n: 20
diff --git a/buildscripts/resmokeconfig/suites/sasl.yml b/buildscripts/resmokeconfig/suites/sasl.yml
index 0d75791d1e6..3333248da7c 100644
--- a/buildscripts/resmokeconfig/suites/sasl.yml
+++ b/buildscripts/resmokeconfig/suites/sasl.yml
@@ -9,3 +9,4 @@ executor:
config:
shell_options:
nodb: ''
+ readMode: commands
diff --git a/buildscripts/resmokeconfig/suites/sharding.yml b/buildscripts/resmokeconfig/suites/sharding.yml
index cbfbb2b28ab..cb084fdbf8d 100644
--- a/buildscripts/resmokeconfig/suites/sharding.yml
+++ b/buildscripts/resmokeconfig/suites/sharding.yml
@@ -12,3 +12,4 @@ executor:
config:
shell_options:
nodb: ''
+ readMode: commands
diff --git a/buildscripts/resmokeconfig/suites/sharding_auth.yml b/buildscripts/resmokeconfig/suites/sharding_auth.yml
index 50874679ea8..37fa3fc58cd 100644
--- a/buildscripts/resmokeconfig/suites/sharding_auth.yml
+++ b/buildscripts/resmokeconfig/suites/sharding_auth.yml
@@ -32,3 +32,4 @@ executor:
keyFile: *keyFile
keyFileData: *keyFileData
nodb: ''
+ readMode: commands
diff --git a/buildscripts/resmokeconfig/suites/sharding_ese.yml b/buildscripts/resmokeconfig/suites/sharding_ese.yml
index e962bfbee3d..2c6887ba8bf 100644
--- a/buildscripts/resmokeconfig/suites/sharding_ese.yml
+++ b/buildscripts/resmokeconfig/suites/sharding_ese.yml
@@ -20,3 +20,4 @@ executor:
TestData:
enableEncryption: ''
encryptionKeyFile: *keyFile
+ readMode: commands
diff --git a/buildscripts/resmokeconfig/suites/sharding_gle_auth_basics_passthrough.yml b/buildscripts/resmokeconfig/suites/sharding_gle_auth_basics_passthrough.yml
index d081d1a8eb9..fa6d00d884d 100644
--- a/buildscripts/resmokeconfig/suites/sharding_gle_auth_basics_passthrough.yml
+++ b/buildscripts/resmokeconfig/suites/sharding_gle_auth_basics_passthrough.yml
@@ -27,6 +27,7 @@ executor:
authenticationMechanism: SCRAM-SHA-1
password: *keyFileData
username: __system
+ readMode: commands
fixture:
class: ShardedClusterFixture
diff --git a/buildscripts/resmokeconfig/suites/sharding_legacy.yml b/buildscripts/resmokeconfig/suites/sharding_legacy.yml
index bdcfbba816b..b0937c27e54 100644
--- a/buildscripts/resmokeconfig/suites/sharding_legacy.yml
+++ b/buildscripts/resmokeconfig/suites/sharding_legacy.yml
@@ -15,3 +15,4 @@ executor:
TestData:
useLegacyConfigServers: true
nodb: ''
+ readMode: legacy
diff --git a/buildscripts/resmokeconfig/suites/snmp.yml b/buildscripts/resmokeconfig/suites/snmp.yml
index 329f06b1020..eb9003e15a4 100644
--- a/buildscripts/resmokeconfig/suites/snmp.yml
+++ b/buildscripts/resmokeconfig/suites/snmp.yml
@@ -9,3 +9,4 @@ executor:
config:
shell_options:
nodb: ''
+ readMode: commands
diff --git a/buildscripts/resmokeconfig/suites/ssl.yml b/buildscripts/resmokeconfig/suites/ssl.yml
index a1885a707d5..06fbd48aef5 100644
--- a/buildscripts/resmokeconfig/suites/ssl.yml
+++ b/buildscripts/resmokeconfig/suites/ssl.yml
@@ -13,3 +13,4 @@ executor:
sslAllowInvalidCertificates: ''
sslCAFile: jstests/libs/ca.pem
sslPEMKeyFile: jstests/libs/client.pem
+ readMode: commands
diff --git a/buildscripts/resmokeconfig/suites/ssl_special.yml b/buildscripts/resmokeconfig/suites/ssl_special.yml
index 340baad9534..3f48f2d217a 100644
--- a/buildscripts/resmokeconfig/suites/ssl_special.yml
+++ b/buildscripts/resmokeconfig/suites/ssl_special.yml
@@ -9,3 +9,4 @@ executor:
config:
shell_options:
nodb: ''
+ readMode: commands
diff --git a/buildscripts/resmokeconfig/suites/tool.yml b/buildscripts/resmokeconfig/suites/tool.yml
index 37ffb69fd73..6b756b62083 100644
--- a/buildscripts/resmokeconfig/suites/tool.yml
+++ b/buildscripts/resmokeconfig/suites/tool.yml
@@ -9,3 +9,4 @@ executor:
config:
shell_options:
nodb: ''
+ readMode: commands
diff --git a/buildscripts/resmokeconfig/suites/with_server.yml b/buildscripts/resmokeconfig/suites/with_server.yml
index c87cad9f8dd..28347632778 100644
--- a/buildscripts/resmokeconfig/suites/with_server.yml
+++ b/buildscripts/resmokeconfig/suites/with_server.yml
@@ -1,5 +1,8 @@
executor:
js_test:
+ config:
+ shell_options:
+ readMode: commands
fixture:
class: MongoDFixture
mongod_options:
diff --git a/buildscripts/resmokelib/parser.py b/buildscripts/resmokelib/parser.py
index 27d4772f705..f3f11012fb3 100644
--- a/buildscripts/resmokelib/parser.py
+++ b/buildscripts/resmokelib/parser.py
@@ -149,7 +149,7 @@ def parse_command_line():
" --shuffle option for producing a consistent test execution order."))
parser.add_option("--shellReadMode", type="choice", action="store", dest="shell_read_mode",
- choices=("commands", "compatibility"), metavar="READ_MODE",
+ choices=("commands", "compatibility", "legacy"), metavar="READ_MODE",
help="The read mode used by the mongo shell.")
parser.add_option("--shellWriteMode", type="choice", action="store", dest="shell_write_mode",
diff --git a/etc/evergreen.yml b/etc/evergreen.yml
index 6ae13bae652..7f4c05ae190 100644
--- a/etc/evergreen.yml
+++ b/etc/evergreen.yml
@@ -678,7 +678,7 @@ tasks:
- func: "do setup"
- func: "run tests"
vars:
- resmoke_args: --suites=gle_auth --shellWriteMode=legacy --storageEngine=mmapv1
+ resmoke_args: --suites=gle_auth --shellWriteMode=legacy --shellReadMode=legacy --storageEngine=mmapv1
- <<: *task_template
name: gle_auth_WT
@@ -686,7 +686,7 @@ tasks:
- func: "do setup"
- func: "run tests"
vars:
- resmoke_args: --suites=gle_auth --shellWriteMode=legacy --storageEngine=wiredTiger
+ resmoke_args: --suites=gle_auth --shellWriteMode=legacy --shellReadMode=legacy --storageEngine=wiredTiger
- <<: *task_template
name: gle_auth_write_cmd
@@ -710,7 +710,7 @@ tasks:
- func: "do setup"
- func: "run tests"
vars:
- resmoke_args: --suites=gle_auth_basics_passthrough --shellWriteMode=legacy --storageEngine=mmapv1
+ resmoke_args: --suites=gle_auth_basics_passthrough --shellWriteMode=legacy --shellReadMode=legacy --storageEngine=mmapv1
- <<: *task_template
name: gle_auth_basics_passthrough_WT
@@ -718,7 +718,7 @@ tasks:
- func: "do setup"
- func: "run tests"
vars:
- resmoke_args: --suites=gle_auth_basics_passthrough --shellWriteMode=legacy --storageEngine=wiredTiger
+ resmoke_args: --suites=gle_auth_basics_passthrough --shellWriteMode=legacy --shellReadMode=legacy --storageEngine=wiredTiger
- <<: *task_template
name: gle_auth_basics_passthrough_write_cmd
@@ -758,7 +758,7 @@ tasks:
- func: "do setup"
- func: "run tests"
vars:
- resmoke_args: --suites=sharding_gle_auth_basics_passthrough --shellWriteMode=legacy --storageEngine=mmapv1
+ resmoke_args: --suites=sharding_gle_auth_basics_passthrough --shellWriteMode=legacy --shellReadMode=legacy --storageEngine=mmapv1
- <<: *task_template
name: sharding_gle_auth_basics_passthrough_WT
@@ -766,7 +766,7 @@ tasks:
- func: "do setup"
- func: "run tests"
vars:
- resmoke_args: --suites=sharding_gle_auth_basics_passthrough --shellWriteMode=legacy --storageEngine=wiredTiger
+ resmoke_args: --suites=sharding_gle_auth_basics_passthrough --shellWriteMode=legacy --shellReadMode=legacy --storageEngine=wiredTiger
- <<: *task_template
name: sharding_gle_auth_basics_passthrough_write_cmd
@@ -816,7 +816,7 @@ tasks:
- func: "do setup"
- func: "run tests"
vars:
- resmoke_args: --suites=core --shellReadMode=compatibility --shellWriteMode=compatibility --storageEngine=mmapv1
+ resmoke_args: --suites=core --shellReadMode=legacy --shellWriteMode=compatibility --storageEngine=mmapv1
run_multiple_jobs: true
- <<: *task_template
@@ -825,7 +825,7 @@ tasks:
- func: "do setup"
- func: "run tests"
vars:
- resmoke_args: --suites=core --shellReadMode=compatibility --shellWriteMode=compatibility --storageEngine=wiredTiger
+ resmoke_args: --suites=core --shellReadMode=legacy --shellWriteMode=compatibility --storageEngine=wiredTiger
run_multiple_jobs: true
- <<: *task_template
@@ -1067,7 +1067,7 @@ tasks:
- func: "do setup"
- func: "run tests"
vars:
- resmoke_args: --suites=parallel --shellReadMode=compatibility --shellWriteMode=compatibility --storageEngine=mmapv1
+ resmoke_args: --suites=parallel --shellReadMode=legacy --shellWriteMode=compatibility --storageEngine=mmapv1
- <<: *task_template
name: parallel_compatibility_WT
@@ -1075,7 +1075,7 @@ tasks:
- func: "do setup"
- func: "run tests"
vars:
- resmoke_args: --suites=parallel --shellReadMode=compatibility --shellWriteMode=compatibility --storageEngine=wiredTiger
+ resmoke_args: --suites=parallel --shellReadMode=legacy --shellWriteMode=compatibility --storageEngine=wiredTiger
- <<: *task_template
name: concurrency
diff --git a/jstests/core/pseudocommand_db.js b/jstests/core/pseudocommand_db.js
index 90a5aa77a0b..3b7a82cd44d 100644
--- a/jstests/core/pseudocommand_db.js
+++ b/jstests/core/pseudocommand_db.js
@@ -1,6 +1,6 @@
(function() {
"use strict";
- if (db.getMongo().readMode() == "compatibility") {
+ if (!db.getMongo().useReadCommands()) {
var testDB = db.getSiblingDB("blah");
// test that we can run the 'inprog' pseudocommand on any database.
assert.commandWorked(testDB.$cmd.sys.inprog.findOne());
diff --git a/jstests/core/type4.js b/jstests/core/type4.js
index c35d7baecca..86e2f32c5d7 100644
--- a/jstests/core/type4.js
+++ b/jstests/core/type4.js
@@ -11,7 +11,7 @@
t.insert({});
t.insert({});
- var oldReadMode = db.getMongo()._readMode;
+ var oldReadMode = db.getMongo().readMode();
assert.throws(function(){
(new _rand())();
@@ -23,7 +23,7 @@
}, [], "invoke constructor on BSON");
assert.throws(function(){
- db.getMongo()._readMode = "commands";
+ db.getMongo().forceReadMode("commands");
var cursor = t.find();
cursor.next();
@@ -31,12 +31,12 @@
}, [], "invoke constructor on CursorHandle");
assert.throws(function(){
- db.getMongo()._readMode = "compatibility";
+ db.getMongo().forceReadMode("legacy");
var cursor = t.find();
cursor.next();
new cursor._cursor();
}, [], "invoke constructor on Cursor");
- db.getMongo()._readMode = oldReadMode;
+ db.getMongo().forceReadMode(oldReadMode);
})();
diff --git a/jstests/core/validate_pseudocommand_ns.js b/jstests/core/validate_pseudocommand_ns.js
index 235d424bb8e..bee314d421d 100644
--- a/jstests/core/validate_pseudocommand_ns.js
+++ b/jstests/core/validate_pseudocommand_ns.js
@@ -1,7 +1,7 @@
// Test that we validate nToReturn when upconverting pseudoCommands.
(function() {
"use strict";
- if (db.getMongo().readMode() === "compatibility") {
+ if (!db.getMongo().useReadCommands()) {
var inprog = db.$cmd.sys.inprog;
// nToReturn must be 1 or -1.
assert.doesNotThrow(function() { inprog.find().limit(-1).next(); });
diff --git a/src/mongo/shell/mongo.js b/src/mongo/shell/mongo.js
index fb6e63583a3..a57a8e1e8dc 100644
--- a/src/mongo/shell/mongo.js
+++ b/src/mongo/shell/mongo.js
@@ -297,27 +297,61 @@ Mongo.prototype.useReadCommands = function() {
}
/**
- * Get the readMode string (either "commands" for find/getMore commands or "compatibility" for
- * OP_QUERY find and OP_GET_MORE).
+ * For testing, forces the shell to use the readMode specified in 'mode'. Must be either "commands"
+ * (use the find/getMore commands), "legacy" (use legacy OP_QUERY/OP_GET_MORE wire protocol reads),
+ * or "compatibility" (auto-detect mode based on wire version).
+ */
+Mongo.prototype.forceReadMode = function(mode) {
+ if (mode !== "commands" && mode !== "compatibility" && mode !== "legacy") {
+ throw new Error("Mode must be one of {commands, compatibility, legacy}, but got: " + mode);
+ }
+
+ this._readMode = mode;
+};
+
+/**
+ * Get the readMode string (either "commands" for find/getMore commands, "legacy" for OP_QUERY find
+ * and OP_GET_MORE, or "compatibility" for detecting based on wire version).
*/
Mongo.prototype.readMode = function() {
- if ("_readMode" in this) {
+ if ("_readMode" in this && this._readMode !== "compatibility") {
// We already have determined our read mode. Just return it.
return this._readMode;
}
- // Determine read mode based on shell params.
- //
- // TODO: Detect what to use based on wire protocol version.
- if (_readMode) {
+ // Get the readMode from the shell params.
+ if (typeof _readMode === "function") {
this._readMode = _readMode();
}
- else {
- this._readMode = "compatibility";
+
+ // If we're in compatibility mode, determine whether the server supports the find/getMore
+ // commands. If it does, use commands mode. If not, degrade to legacy mode.
+ if (this._readMode === "compatibility") {
+ try {
+ var isMaster = this.getDB("admin").runCommand({isMaster: 1});
+ var hasReadCommands = (isMaster.ok && 'minWireVersion' in isMaster &&
+ 'maxWireVersion' in isMaster &&
+ isMaster.minWireVersion <= 4 &&
+ 4 <= isMaster.maxWireVersion);
+
+ if (hasReadCommands) {
+ this._readMode = "commands";
+ }
+ else {
+ print("Cannot use 'commands' readMode, degrading to 'legacy' mode");
+ this._readMode = "legacy";
+ }
+ }
+ catch (e) {
+ // We failed trying to determine whether the remote node supports the find/getMore
+ // commands. In this case, we keep _readMode as "compatibility" and the shell should
+ // issue legacy reads. Next time around we will issue another isMaster to try to
+ // determine the readMode decisively.
+ }
}
return this._readMode;
-}
+};
//
// Write Concern can be set at the connection level, and is used for all write operations unless
diff --git a/src/mongo/shell/shell_options.cpp b/src/mongo/shell/shell_options.cpp
index a54f2bbc567..7f296a0b0cb 100644
--- a/src/mongo/shell/shell_options.cpp
+++ b/src/mongo/shell/shell_options.cpp
@@ -156,7 +156,7 @@ Status addMongoShellOptions(moe::OptionSection* options) {
"readMode",
moe::String,
"mode to determine how .find() queries are done:"
- " commands, compatibility").hidden();
+ " commands, compatibility, legacy").hidden();
options->addOptionChaining("rpcProtocols",
"rpcProtocols",
@@ -279,11 +279,12 @@ Status storeMongoShellOptions(const moe::Environment& params,
}
if (params.count("readMode")) {
std::string mode = params["readMode"].as<string>();
- if (mode != "commands" && mode != "compatibility") {
- throw MsgAssertionException(17397,
- mongoutils::str::stream()
- << "Unknown readMode option: '" << mode
- << "'. Valid modes are: {commands, compatibility}");
+ if (mode != "commands" && mode != "compatibility" && mode != "legacy") {
+ throw MsgAssertionException(
+ 17397,
+ mongoutils::str::stream()
+ << "Unknown readMode option: '" << mode
+ << "'. Valid modes are: {commands, compatibility, legacy}");
}
shellGlobalParams.readMode = mode;
}
diff --git a/src/mongo/shell/utils.js b/src/mongo/shell/utils.js
index ed33bc5ea23..8ba63e71e73 100644
--- a/src/mongo/shell/utils.js
+++ b/src/mongo/shell/utils.js
@@ -402,7 +402,7 @@ if (typeof(_writeMode) == 'undefined') {
if (typeof(_readMode) == 'undefined') {
// This is for cases when the v8 engine is used other than the mongo shell, like map reduce.
- _readMode = function() { return "compatibility"; };
+ _readMode = function() { return "legacy"; };
};
shellPrintHelper = function (x) {