summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Pasette <dan@10gen.com>2013-10-02 18:59:37 -0400
committerDan Pasette <dan@mongodb.com>2013-10-03 14:44:06 -0400
commit22252fdaa6ec8744bb191c3d09d84e5e6e3f4058 (patch)
tree949ae3f8b79d916e5fe219efc82d47adf9a610d1
parent9c032a641b278715e71129efe100db2b570ceeb0 (diff)
downloadmongo-22252fdaa6ec8744bb191c3d09d84e5e6e3f4058.tar.gz
SERVER-10594 slaveOk bit ignored for unsharded aggregate
Backport of original commit: 84ff1694c4bf92f3deef5c013ac9a5b912e6f96f
-rw-r--r--jstests/aggregation/mongos_slaveok.js41
-rw-r--r--src/mongo/s/commands_public.cpp2
2 files changed, 42 insertions, 1 deletions
diff --git a/jstests/aggregation/mongos_slaveok.js b/jstests/aggregation/mongos_slaveok.js
new file mode 100644
index 00000000000..057aacd9efa
--- /dev/null
+++ b/jstests/aggregation/mongos_slaveok.js
@@ -0,0 +1,41 @@
+/**
+ * Tests aggregate command against mongos with slaveOk. For more tests on read preference,
+ * please refer to jstests/sharding/read_pref_cmd.js.
+ */
+
+var NODES = 2;
+
+var doTest = function(st, doSharded) {
+var testDB = st.s.getDB('test');
+
+testDB.adminCommand({ enableSharding: 'test' });
+testDB.adminCommand({ shardCollection: 'test.user', key: { x: 1 }});
+
+if (doSharded) {
+ testDB.adminCommand({ enableSharding: 'test' });
+ testDB.adminCommand({ shardCollection: 'test.user', key: { x: 1 }});
+}
+
+testDB.user.insert({ x: 10 });
+testDB.runCommand({ getLastError: 1, w: NODES });
+testDB.setSlaveOk(true);
+
+var secNode = st.rs0.getSecondary();
+secNode.getDB('test').setProfilingLevel(2);
+
+var res = testDB.runCommand({ aggregate: 'user', pipeline: [{ $project: { x: 1 }}]});
+assert(res.ok);
+
+var profileQuery = { op: 'command', ns: 'test.$cmd', 'command.aggregate': 'user' };
+var profileDoc = secNode.getDB('test').system.profile.findOne(profileQuery);
+
+assert(profileDoc != null);
+testDB.dropDatabase();
+};
+
+var st = new ShardingTest({ shards: { rs0: { oplogSize: 10, verbose: 1, nodes: NODES }}});
+
+doTest(st, false);
+doTest(st, true);
+
+st.stop();
diff --git a/src/mongo/s/commands_public.cpp b/src/mongo/s/commands_public.cpp
index 1c2ff52364a..bddb53c885a 100644
--- a/src/mongo/s/commands_public.cpp
+++ b/src/mongo/s/commands_public.cpp
@@ -1815,7 +1815,7 @@ namespace mongo {
*/
DBConfigPtr conf(grid.getDBConfig(dbName , false));
if (!conf || !conf->isShardingEnabled() || !conf->isSharded(fullns))
- return passthrough(conf, cmdObj, result);
+ return passthrough(conf, cmdObj, options, result);
/* split the pipeline into pieces for mongods and this mongos */
intrusive_ptr<Pipeline> pShardPipeline(