summaryrefslogtreecommitdiff
path: root/jstests/sharding/mr_and_agg_versioning.js
diff options
context:
space:
mode:
authorCharlie Swanson <charlie.swanson@mongodb.com>2019-09-27 17:01:34 +0000
committerevergreen <evergreen@mongodb.com>2019-09-27 17:01:34 +0000
commitb16985b58e7fd01dd33403af0d83de72e2df1624 (patch)
treef906146809d4079dd4a3913a36876cb34c84537c /jstests/sharding/mr_and_agg_versioning.js
parente2875bb82ff99ffb27ccbcd68d596941a427f151 (diff)
downloadmongo-b16985b58e7fd01dd33403af0d83de72e2df1624.tar.gz
SERVER-42691 Modernize mapReduce tests in sharding directory
Diffstat (limited to 'jstests/sharding/mr_and_agg_versioning.js')
-rw-r--r--jstests/sharding/mr_and_agg_versioning.js52
1 files changed, 24 insertions, 28 deletions
diff --git a/jstests/sharding/mr_and_agg_versioning.js b/jstests/sharding/mr_and_agg_versioning.js
index e0cb7c94d26..552c43aadc3 100644
--- a/jstests/sharding/mr_and_agg_versioning.js
+++ b/jstests/sharding/mr_and_agg_versioning.js
@@ -2,62 +2,58 @@
(function() {
"use strict";
-var st = new ShardingTest({shards: 2, mongos: 3});
+const st = new ShardingTest({shards: 2, mongos: 3});
-var dbName = jsTest.name();
-var collName = dbName + ".coll";
-var numDocs = 50000;
-var numKeys = 1000;
+const dbName = jsTest.name();
+const nsString = dbName + ".coll";
+const numDocs = 50000;
+const numKeys = 1000;
st.s.adminCommand({enableSharding: dbName});
st.ensurePrimaryShard(dbName, st.shard0.shardName);
-st.s.adminCommand({shardCollection: collName, key: {key: 1}});
+st.s.adminCommand({shardCollection: nsString, key: {key: 1}});
// Load chunk data to the stale mongoses before moving a chunk
-var staleMongos1 = st.s1;
-var staleMongos2 = st.s2;
-staleMongos1.getCollection(collName).find().itcount();
-staleMongos2.getCollection(collName).find().itcount();
+const staleMongos1 = st.s1;
+const staleMongos2 = st.s2;
+staleMongos1.getCollection(nsString).find().itcount();
+staleMongos2.getCollection(nsString).find().itcount();
-st.s.adminCommand({split: collName, middle: {key: numKeys / 2}});
-st.s.adminCommand({moveChunk: collName, find: {key: 0}, to: st.shard1.shardName});
+st.s.adminCommand({split: nsString, middle: {key: numKeys / 2}});
+st.s.adminCommand({moveChunk: nsString, find: {key: 0}, to: st.shard1.shardName});
-var bulk = st.s.getCollection(collName).initializeUnorderedBulkOp();
-for (var i = 0; i < numDocs; i++) {
+const bulk = st.s.getCollection(nsString).initializeUnorderedBulkOp();
+for (let i = 0; i < numDocs; i++) {
bulk.insert({_id: i, key: (i % numKeys), value: i % numKeys});
}
assert.commandWorked(bulk.execute());
// Add orphaned documents directly to the shards to ensure they are properly filtered out.
-st.shard0.getCollection(collName).insert({_id: 0, key: 0, value: 0});
-st.shard1.getCollection(collName).insert({_id: numDocs, key: numKeys, value: numKeys});
+st.shard0.getCollection(nsString).insert({_id: 0, key: 0, value: 0});
+st.shard1.getCollection(nsString).insert({_id: numDocs, key: numKeys, value: numKeys});
-jsTest.log("Doing mapReduce");
-
-var map = function() {
+const map = function() {
emit(this.key, this.value);
};
-var reduce = function(k, values) {
- var total = 0;
- for (var i = 0; i < values.length; i++) {
+const reduce = function(k, values) {
+ let total = 0;
+ for (let i = 0; i < values.length; i++) {
total += values[i];
}
return total;
};
function validateOutput(output) {
assert.eq(output.length, numKeys, tojson(output));
- for (var i = 0; i < output.length; i++) {
+ for (let i = 0; i < output.length; i++) {
assert.eq(output[i]._id * (numDocs / numKeys), output[i].value, tojson(output));
}
}
-var res = staleMongos1.getCollection(collName).mapReduce(map, reduce, {out: {inline: 1}});
+let res = staleMongos1.getCollection(nsString).mapReduce(map, reduce, {out: {inline: 1}});
validateOutput(res.results);
-jsTest.log("Doing aggregation");
-
-res = staleMongos2.getCollection(collName).aggregate(
- [{'$group': {_id: "$key", value: {"$sum": "$value"}}}, {'$sort': {_id: 1}}]);
+res = staleMongos2.getCollection(nsString).aggregate(
+ [{$group: {_id: "$key", value: {$sum: "$value"}}}, {$sort: {_id: 1}}]);
validateOutput(res.toArray());
st.stop();