summaryrefslogtreecommitdiff
path: root/jstests/aggregation
diff options
context:
space:
mode:
authorMark Benvenuto <mark.benvenuto@mongodb.com>2016-05-28 17:55:12 -0400
committerMark Benvenuto <mark.benvenuto@mongodb.com>2016-05-28 17:55:12 -0400
commit6dcdd23dd37ef12c87e71cf59ef01cd82432efe0 (patch)
treec8cfb5acb62c80f375bc37e7d4350382deea6a37 /jstests/aggregation
parentd4ac5673ea3f6cef4ce9dbcec90e31813997a528 (diff)
downloadmongo-6dcdd23dd37ef12c87e71cf59ef01cd82432efe0.tar.gz
SERVER-23971 Clang-Format code
Diffstat (limited to 'jstests/aggregation')
-rw-r--r--jstests/aggregation/bugs/cond.js25
-rw-r--r--jstests/aggregation/bugs/firstlast.js16
-rw-r--r--jstests/aggregation/bugs/match.js14
-rw-r--r--jstests/aggregation/bugs/server10176.js43
-rw-r--r--jstests/aggregation/bugs/server11118.js58
-rw-r--r--jstests/aggregation/bugs/server11675.js78
-rw-r--r--jstests/aggregation/bugs/server12015.js5
-rw-r--r--jstests/aggregation/bugs/server14670.js4
-rw-r--r--jstests/aggregation/bugs/server17943.js46
-rw-r--r--jstests/aggregation/bugs/server18198.js8
-rw-r--r--jstests/aggregation/bugs/server18222.js7
-rw-r--r--jstests/aggregation/bugs/server19095.js174
-rw-r--r--jstests/aggregation/bugs/server20163.js109
-rw-r--r--jstests/aggregation/bugs/server20169.js16
-rw-r--r--jstests/aggregation/bugs/server21632.js5
-rw-r--r--jstests/aggregation/bugs/server22093.js5
-rw-r--r--jstests/aggregation/bugs/server22580.js12
-rw-r--r--jstests/aggregation/bugs/server3253.js16
-rw-r--r--jstests/aggregation/bugs/server4588.js16
-rw-r--r--jstests/aggregation/bugs/server5044.js12
-rw-r--r--jstests/aggregation/bugs/server6121.js30
-rw-r--r--jstests/aggregation/bugs/server6125.js4
-rw-r--r--jstests/aggregation/bugs/server6131.js36
-rw-r--r--jstests/aggregation/bugs/server6179.js8
-rw-r--r--jstests/aggregation/bugs/server6189.js86
-rw-r--r--jstests/aggregation/bugs/server6190.js5
-rw-r--r--jstests/aggregation/bugs/server6195.js2
-rw-r--r--jstests/aggregation/bugs/server6529.js14
-rw-r--r--jstests/aggregation/bugs/server6531.js8
-rw-r--r--jstests/aggregation/bugs/server6556.js12
-rw-r--r--jstests/aggregation/bugs/server7781.js12
-rw-r--r--jstests/aggregation/bugs/server9840.js109
-rw-r--r--jstests/aggregation/bugs/server9841.js25
-rw-r--r--jstests/aggregation/bugs/substr.js26
-rw-r--r--jstests/aggregation/bugs/upperlower.js5
-rw-r--r--jstests/aggregation/expressions/expression_mod.js79
-rw-r--r--jstests/aggregation/expressions/in.js46
-rw-r--r--jstests/aggregation/expressions/indexof_array.js16
-rw-r--r--jstests/aggregation/expressions/indexof_bytes.js20
-rw-r--r--jstests/aggregation/expressions/indexof_codepoints.js20
-rw-r--r--jstests/aggregation/expressions/reduce.js90
-rw-r--r--jstests/aggregation/expressions/split.js24
-rw-r--r--jstests/aggregation/expressions/switch.js6
-rw-r--r--jstests/aggregation/expressions/switch_errors.js28
-rw-r--r--jstests/aggregation/extras/mrabench.js11
-rw-r--r--jstests/aggregation/extras/testutils.js8
-rw-r--r--jstests/aggregation/extras/utils.js8
-rw-r--r--jstests/aggregation/mongos_slaveok.js5
-rw-r--r--jstests/aggregation/sources/graphLookup/airports.js78
-rw-r--r--jstests/aggregation/sources/graphLookup/basic.js148
-rw-r--r--jstests/aggregation/sources/graphLookup/error.js40
-rw-r--r--jstests/aggregation/sources/graphLookup/nested_objects.js60
-rw-r--r--jstests/aggregation/sources/graphLookup/sharded.js3
-rw-r--r--jstests/aggregation/sources/graphLookup/socialite.js26
-rw-r--r--jstests/aggregation/testSlave.js4
-rw-r--r--jstests/aggregation/testall.js31
-rw-r--r--jstests/aggregation/testshard1.js83
-rw-r--r--jstests/aggregation/unwind.js7
58 files changed, 831 insertions, 1061 deletions
diff --git a/jstests/aggregation/bugs/cond.js b/jstests/aggregation/bugs/cond.js
index 2b4fa8ff16e..c48c6b724f0 100644
--- a/jstests/aggregation/bugs/cond.js
+++ b/jstests/aggregation/bugs/cond.js
@@ -68,16 +68,15 @@ t.save({noonSense: 'pm', mealCombined: 'yes'});
t.save({noonSense: 'pm', mealCombined: 'no'});
assert.eq(['breakfast', 'brunch', 'linner', 'dinner'],
t.aggregate({
- $project: {
- a: {
- $cond: [
- {$eq: ['$noonSense', 'am']},
- {$cond: [{$eq: ['$mealCombined', 'yes']}, 'brunch', 'breakfast']},
- {$cond: [{$eq: ['$mealCombined', 'yes']}, 'linner', 'dinner']}
- ]
- }
- }
- })
- .map(function(x) {
- return x.a;
- }));
+ $project: {
+ a: {
+ $cond: [
+ {$eq: ['$noonSense', 'am']},
+ {$cond: [{$eq: ['$mealCombined', 'yes']}, 'brunch', 'breakfast']},
+ {$cond: [{$eq: ['$mealCombined', 'yes']}, 'linner', 'dinner']}
+ ]
+ }
+ }
+ }).map(function(x) {
+ return x.a;
+ }));
diff --git a/jstests/aggregation/bugs/firstlast.js b/jstests/aggregation/bugs/firstlast.js
index ca9e963f6ca..54f0f8be0e9 100644
--- a/jstests/aggregation/bugs/firstlast.js
+++ b/jstests/aggregation/bugs/firstlast.js
@@ -104,17 +104,5 @@ assertFirstLast([1, 2], [6], [], '$b.c');
t.drop();
t.save({a: 1, b: 1});
t.save({a: 1, b: 2});
-assertFirstLast(1,
- 0,
- [],
- {
-$mod:
- ['$b', 2]
- });
-assertFirstLast(0,
- 1,
- [],
- {
-$mod:
- [{$add: ['$b', 1]}, 2]
- });
+assertFirstLast(1, 0, [], {$mod: ['$b', 2]});
+assertFirstLast(0, 1, [], {$mod: [{$add: ['$b', 1]}, 2]});
diff --git a/jstests/aggregation/bugs/match.js b/jstests/aggregation/bugs/match.js
index fbc467812d7..2ee646dac7e 100644
--- a/jstests/aggregation/bugs/match.js
+++ b/jstests/aggregation/bugs/match.js
@@ -13,9 +13,7 @@ identityProjection = {
/** Assert that an aggregation generated the expected error. */
function assertError(expectedCode, matchSpec) {
- matchStage = {
- $match: matchSpec
- };
+ matchStage = {$match: matchSpec};
// Check where matching is folded in to DocumentSourceCursor.
assertErrorCode(t, [matchStage], expectedCode);
// Check where matching is not folded in to DocumentSourceCursor.
@@ -41,9 +39,7 @@ function assertResults(expectedResults, matchSpec) {
if (expectedResults) {
assertEqualResultsUnordered(expectedResults, findResults);
}
- matchStage = {
- $match: matchSpec
- };
+ matchStage = {$match: matchSpec};
// Check where matching is folded in to DocumentSourceCursor.
assertEqualResultsUnordered(findResults, t.aggregate(matchStage).toArray());
// Check where matching is not folded in to DocumentSourceCursor.
@@ -176,11 +172,7 @@ function checkMatchResults(indexed) {
// $and
assertResults([{_id: 1, a: 2}], {$and: [{a: 2}, {_id: 1}]});
- assertResults([],
- {
- $and:
- [{a: 1}, {_id: 1}]
- });
+ assertResults([], {$and: [{a: 1}, {_id: 1}]});
assertResults([{_id: 1, a: 2}, {_id: 2, a: 3}],
{$and: [{$or: [{_id: 1}, {a: 3}]}, {$or: [{_id: 2}, {a: 2}]}]});
diff --git a/jstests/aggregation/bugs/server10176.js b/jstests/aggregation/bugs/server10176.js
index 5a56585265d..b04db0c4319 100644
--- a/jstests/aggregation/bugs/server10176.js
+++ b/jstests/aggregation/bugs/server10176.js
@@ -33,28 +33,27 @@ load('jstests/aggregation/extras/utils.js');
// valid use of $abs: numbers become positive, null/undefined/nonexistent become null
var results = coll.aggregate([{$project: {a: {$abs: "$a"}}}]).toArray();
- assert.eq(results,
- [
- {_id: 0, a: 5},
- {_id: 1, a: 5},
- {_id: 2, a: 5.5},
- {_id: 3, a: 5.5},
- {_id: 4, a: 5},
- {_id: 5, a: 5},
- {_id: 6, a: NumberLong("5")},
- {_id: 7, a: NumberLong("5")},
- {_id: 8, a: 0},
- {_id: 9, a: 0},
- {_id: 10, a: 0},
- {_id: 11, a: NumberLong(Math.pow(2, 31))},
- {_id: 12, a: Math.pow(2, 31)},
- {_id: 13, a: NumberLong("1152921504606846977")},
- {_id: 14, a: NumberLong("1152921504606846977")},
- {_id: 15, a: null},
- {_id: 16, a: null},
- {_id: 17, a: NaN},
- {_id: 18, a: null},
- ]);
+ assert.eq(results, [
+ {_id: 0, a: 5},
+ {_id: 1, a: 5},
+ {_id: 2, a: 5.5},
+ {_id: 3, a: 5.5},
+ {_id: 4, a: 5},
+ {_id: 5, a: 5},
+ {_id: 6, a: NumberLong("5")},
+ {_id: 7, a: NumberLong("5")},
+ {_id: 8, a: 0},
+ {_id: 9, a: 0},
+ {_id: 10, a: 0},
+ {_id: 11, a: NumberLong(Math.pow(2, 31))},
+ {_id: 12, a: Math.pow(2, 31)},
+ {_id: 13, a: NumberLong("1152921504606846977")},
+ {_id: 14, a: NumberLong("1152921504606846977")},
+ {_id: 15, a: null},
+ {_id: 16, a: null},
+ {_id: 17, a: NaN},
+ {_id: 18, a: null},
+ ]);
// Invalid
// using $abs on string
diff --git a/jstests/aggregation/bugs/server11118.js b/jstests/aggregation/bugs/server11118.js
index da4e9862bad..3d2813ed8ae 100644
--- a/jstests/aggregation/bugs/server11118.js
+++ b/jstests/aggregation/bugs/server11118.js
@@ -9,9 +9,13 @@ function testFormat(date, formatStr, expectedStr) {
db.dates.drop();
db.dates.insert({date: date});
- var res = db.dates.aggregate([{
- $project: {_id: 0, formatted: {$dateToString: {format: formatStr, date: "$date"}}}
- }]).toArray();
+ var res =
+ db.dates
+ .aggregate([{
+ $project:
+ {_id: 0, formatted: {$dateToString: {format: formatStr, date: "$date"}}}
+ }])
+ .toArray();
assert.eq(res[0].formatted, expectedStr);
}
@@ -36,18 +40,16 @@ function testDateValueError(dateVal, errCode) {
var now = ISODate();
// Use all modifiers we can test with js provided function
-testFormat(now,
- "%%-%Y-%m-%d-%H-%M-%S-%L",
- [
- "%",
- now.getUTCFullYear().zeroPad(4),
- (now.getUTCMonth() + 1).zeroPad(2),
- now.getUTCDate().zeroPad(2),
- now.getUTCHours().zeroPad(2),
- now.getUTCMinutes().zeroPad(2),
- now.getUTCSeconds().zeroPad(2),
- now.getUTCMilliseconds().zeroPad(3)
- ].join("-"));
+testFormat(now, "%%-%Y-%m-%d-%H-%M-%S-%L", [
+ "%",
+ now.getUTCFullYear().zeroPad(4),
+ (now.getUTCMonth() + 1).zeroPad(2),
+ now.getUTCDate().zeroPad(2),
+ now.getUTCHours().zeroPad(2),
+ now.getUTCMinutes().zeroPad(2),
+ now.getUTCSeconds().zeroPad(2),
+ now.getUTCMilliseconds().zeroPad(3)
+].join("-"));
// Padding tests
var padme = ISODate("2001-02-03T04:05:06.007Z");
@@ -62,20 +64,18 @@ testFormat(padme, "%S", padme.getUTCSeconds().zeroPad(2));
testFormat(padme, "%L", padme.getUTCMilliseconds().zeroPad(3));
// no space and multiple characters between modifiers
-testFormat(now,
- "%d%d***%d***%d**%d*%d",
- [
- now.getUTCDate().zeroPad(2),
- now.getUTCDate().zeroPad(2),
- "***",
- now.getUTCDate().zeroPad(2),
- "***",
- now.getUTCDate().zeroPad(2),
- "**",
- now.getUTCDate().zeroPad(2),
- "*",
- now.getUTCDate().zeroPad(2)
- ].join(""));
+testFormat(now, "%d%d***%d***%d**%d*%d", [
+ now.getUTCDate().zeroPad(2),
+ now.getUTCDate().zeroPad(2),
+ "***",
+ now.getUTCDate().zeroPad(2),
+ "***",
+ now.getUTCDate().zeroPad(2),
+ "**",
+ now.getUTCDate().zeroPad(2),
+ "*",
+ now.getUTCDate().zeroPad(2)
+].join(""));
// JS doesn't have equivalents of these format specifiers
testFormat(ISODate('1999-01-02 03:04:05.006Z'), "%U-%w-%j", "00-7-002");
diff --git a/jstests/aggregation/bugs/server11675.js b/jstests/aggregation/bugs/server11675.js
index 709120c27ca..a38570dc8cd 100644
--- a/jstests/aggregation/bugs/server11675.js
+++ b/jstests/aggregation/bugs/server11675.js
@@ -88,57 +88,57 @@ var server11675 = function() {
return obj;
});
var res = t.aggregate([
- {$match: {$text: {$search: 'apple banana'}}},
- {$sort: {textScore: {$meta: 'textScore'}}}
- ]).toArray();
+ {$match: {$text: {$search: 'apple banana'}}},
+ {$sort: {textScore: {$meta: 'textScore'}}}
+ ]).toArray();
assert.eq(res, findRes);
// Make sure {$meta: 'textScore'} can be used as a sub-expression
var res = t.aggregate([
- {$match: {_id: 1, $text: {$search: 'apple'}}},
- {
- $project: {
- words: 1,
- score: {$meta: 'textScore'},
- wordsTimesScore: {$multiply: ['$words', {$meta: 'textScore'}]}
- }
- }
- ]).toArray();
+ {$match: {_id: 1, $text: {$search: 'apple'}}},
+ {
+ $project: {
+ words: 1,
+ score: {$meta: 'textScore'},
+ wordsTimesScore: {$multiply: ['$words', {$meta: 'textScore'}]}
+ }
+ }
+ ]).toArray();
assert.eq(res[0].wordsTimesScore, res[0].words * res[0].score, tojson(res));
// And can be used in $group
var res = t.aggregate([
- {$match: {_id: 1, $text: {$search: 'apple banana'}}},
- {$group: {_id: {$meta: 'textScore'}, score: {$first: {$meta: 'textScore'}}}}
- ]).toArray();
+ {$match: {_id: 1, $text: {$search: 'apple banana'}}},
+ {$group: {_id: {$meta: 'textScore'}, score: {$first: {$meta: 'textScore'}}}}
+ ]).toArray();
assert.eq(res[0]._id, res[0].score, tojson(res));
// Make sure metadata crosses shard -> merger boundary
var res = t.aggregate([
- {$match: {_id: 1, $text: {$search: 'apple'}}},
- {$project: {scoreOnShard: {$meta: 'textScore'}}},
- {$limit: 1} // force a split. later stages run on merger
- ,
- {$project: {scoreOnShard: 1, scoreOnMerger: {$meta: 'textScore'}}}
- ]).toArray();
+ {$match: {_id: 1, $text: {$search: 'apple'}}},
+ {$project: {scoreOnShard: {$meta: 'textScore'}}},
+ {$limit: 1} // force a split. later stages run on merger
+ ,
+ {$project: {scoreOnShard: 1, scoreOnMerger: {$meta: 'textScore'}}}
+ ]).toArray();
assert.eq(res[0].scoreOnMerger, res[0].scoreOnShard);
var score = res[0].scoreOnMerger; // save for later tests
// Make sure metadata crosses shard -> merger boundary even if not used on shard
var res = t.aggregate([
- {$match: {_id: 1, $text: {$search: 'apple'}}},
- {$limit: 1} // force a split. later stages run on merger
- ,
- {$project: {scoreOnShard: 1, scoreOnMerger: {$meta: 'textScore'}}}
- ]).toArray();
+ {$match: {_id: 1, $text: {$search: 'apple'}}},
+ {$limit: 1} // force a split. later stages run on merger
+ ,
+ {$project: {scoreOnShard: 1, scoreOnMerger: {$meta: 'textScore'}}}
+ ]).toArray();
assert.eq(res[0].scoreOnMerger, score);
// Make sure metadata works if first $project doesn't use it.
var res = t.aggregate([
- {$match: {_id: 1, $text: {$search: 'apple'}}},
- {$project: {_id: 1}},
- {$project: {_id: 1, score: {$meta: 'textScore'}}}
- ]).toArray();
+ {$match: {_id: 1, $text: {$search: 'apple'}}},
+ {$project: {_id: 1}},
+ {$project: {_id: 1, score: {$meta: 'textScore'}}}
+ ]).toArray();
assert.eq(res[0].score, score);
// Make sure the metadata is 'missing()' when it doesn't exist because it was never created
@@ -147,20 +147,20 @@ var server11675 = function() {
// Make sure the metadata is 'missing()' when it doesn't exist because the document changed
var res = t.aggregate([
- {$match: {_id: 1, $text: {$search: 'apple banana'}}},
- {$group: {_id: 1, score: {$first: {$meta: 'textScore'}}}},
- {$project: {_id: 1, scoreAgain: {$meta: 'textScore'}}},
- ]).toArray();
+ {$match: {_id: 1, $text: {$search: 'apple banana'}}},
+ {$group: {_id: 1, score: {$first: {$meta: 'textScore'}}}},
+ {$project: {_id: 1, scoreAgain: {$meta: 'textScore'}}},
+ ]).toArray();
assert(!("scoreAgain" in res[0]));
// Make sure metadata works after a $unwind
t.insert({_id: 5, text: 'mango', words: [1, 2, 3]});
var res = t.aggregate([
- {$match: {$text: {$search: 'mango'}}},
- {$project: {score: {$meta: "textScore"}, _id: 1, words: 1}},
- {$unwind: '$words'},
- {$project: {scoreAgain: {$meta: "textScore"}, score: 1}}
- ]).toArray();
+ {$match: {$text: {$search: 'mango'}}},
+ {$project: {score: {$meta: "textScore"}, _id: 1, words: 1}},
+ {$unwind: '$words'},
+ {$project: {scoreAgain: {$meta: "textScore"}, score: 1}}
+ ]).toArray();
assert.eq(res[0].scoreAgain, res[0].score);
// Error checking
diff --git a/jstests/aggregation/bugs/server12015.js b/jstests/aggregation/bugs/server12015.js
index af4ee75f92d..c237e4f6f90 100644
--- a/jstests/aggregation/bugs/server12015.js
+++ b/jstests/aggregation/bugs/server12015.js
@@ -12,10 +12,7 @@ load("jstests/aggregation/extras/utils.js"); // For orderedArrayEq.
"use strict";
var coll = db.server12015;
coll.drop();
- var indexSpec = {
- a: 1,
- b: 1
- };
+ var indexSpec = {a: 1, b: 1};
assert.writeOK(coll.insert({_id: 0, a: 0, b: 0}));
assert.writeOK(coll.insert({_id: 1, a: 0, b: 1}));
diff --git a/jstests/aggregation/bugs/server14670.js b/jstests/aggregation/bugs/server14670.js
index 92c6e98e8e1..dc8a750e9db 100644
--- a/jstests/aggregation/bugs/server14670.js
+++ b/jstests/aggregation/bugs/server14670.js
@@ -12,12 +12,12 @@ load("jstests/aggregation/extras/utils.js"); // For assertErrorCode.
coll.insert({});
assertErrorCode(coll,
- [{$project: {strLen: {$strLenBytes: 1}}}],
+ [{$project: {strLen: {$strLenBytes: 1}}}],
34473,
"$strLenBytes requires a string argument.");
assertErrorCode(coll,
- [{$project: {strLen: {$strLenCP: 1}}}],
+ [{$project: {strLen: {$strLenCP: 1}}}],
34471,
"$strLenCP requires a string argument.");
}());
diff --git a/jstests/aggregation/bugs/server17943.js b/jstests/aggregation/bugs/server17943.js
index 10dbac2c37a..7036a16b940 100644
--- a/jstests/aggregation/bugs/server17943.js
+++ b/jstests/aggregation/bugs/server17943.js
@@ -18,11 +18,7 @@ load('jstests/aggregation/extras/utils.js');
assert.writeOK(coll.insert({_id: 6}));
// Create filter to only accept odd numbers.
- filterDoc = {
- input: '$a',
- as: 'x',
- cond: {$eq: [1, {$mod: ['$$x', 2]}]}
- };
+ filterDoc = {input: '$a', as: 'x', cond: {$eq: [1, {$mod: ['$$x', 2]}]}};
var expectedResults = [
{_id: 0, b: [1, 3, 5]},
{_id: 1, b: []},
@@ -45,57 +41,31 @@ load('jstests/aggregation/extras/utils.js');
assertErrorCode(coll, [{$project: {b: {$filter: filterDoc}}}], 28646);
// Extra field(s).
- filterDoc = {
- input: '$a',
- as: 'x',
- cond: true,
- extra: 1
- };
+ filterDoc = {input: '$a', as: 'x', cond: true, extra: 1};
assertErrorCode(coll, [{$project: {b: {$filter: filterDoc}}}], 28647);
// Missing 'input'.
- filterDoc = {
- as: 'x',
- cond: true
- };
+ filterDoc = {as: 'x', cond: true};
assertErrorCode(coll, [{$project: {b: {$filter: filterDoc}}}], 28648);
// Missing 'as'.
- filterDoc = {
- input: '$a',
- cond: true
- };
+ filterDoc = {input: '$a', cond: true};
assertErrorCode(coll, [{$project: {b: {$filter: filterDoc}}}], 28649);
// Missing 'cond'.
- filterDoc = {
- input: '$a',
- as: 'x'
- };
+ filterDoc = {input: '$a', as: 'x'};
assertErrorCode(coll, [{$project: {b: {$filter: filterDoc}}}], 28650);
// 'as' is not a valid variable name.
- filterDoc = {
- input: '$a',
- as: '$x',
- cond: true
- };
+ filterDoc = {input: '$a', as: '$x', cond: true};
assertErrorCode(coll, [{$project: {b: {$filter: filterDoc}}}], 16867);
// 'input' is not an array.
- filterDoc = {
- input: 'string',
- as: 'x',
- cond: true
- };
+ filterDoc = {input: 'string', as: 'x', cond: true};
assertErrorCode(coll, [{$project: {b: {$filter: filterDoc}}}], 28651);
coll.drop();
assert.writeOK(coll.insert({a: 'string'}));
- filterDoc = {
- input: '$a',
- as: 'x',
- cond: true
- };
+ filterDoc = {input: '$a', as: 'x', cond: true};
assertErrorCode(coll, [{$project: {b: {$filter: filterDoc}}}], 28651);
}());
diff --git a/jstests/aggregation/bugs/server18198.js b/jstests/aggregation/bugs/server18198.js
index 39cb37074e5..19b355f4953 100644
--- a/jstests/aggregation/bugs/server18198.js
+++ b/jstests/aggregation/bugs/server18198.js
@@ -16,14 +16,10 @@
},
runCommand: function(db, cmd, opts) {
commandsRan.push({db: db, cmd: cmd, opts: opts});
- return {
- ok: 1.0
- };
+ return {ok: 1.0};
},
getReadPref: function() {
- return {
- mode: "secondaryPreferred"
- };
+ return {mode: "secondaryPreferred"};
},
getReadPrefMode: function() {
return "secondaryPreferred";
diff --git a/jstests/aggregation/bugs/server18222.js b/jstests/aggregation/bugs/server18222.js
index 1a46ff349c8..cea52b3970d 100644
--- a/jstests/aggregation/bugs/server18222.js
+++ b/jstests/aggregation/bugs/server18222.js
@@ -20,8 +20,11 @@
assert.writeOK(coll.insert({_id: 10, x: ['0']}));
// Project field is_array to represent whether the field x was an array.
- var results =
- coll.aggregate([{$sort: {_id: 1}}, {$project: {isArray: {$isArray: '$x'}}}, ]).toArray();
+ var results = coll.aggregate([
+ {$sort: {_id: 1}},
+ {$project: {isArray: {$isArray: '$x'}}},
+ ])
+ .toArray();
var expectedResults = [
{_id: 0, isArray: false},
{_id: 1, isArray: false},
diff --git a/jstests/aggregation/bugs/server19095.js b/jstests/aggregation/bugs/server19095.js
index 30d2610aad9..875a7d16a9d 100644
--- a/jstests/aggregation/bugs/server19095.js
+++ b/jstests/aggregation/bugs/server19095.js
@@ -55,11 +55,10 @@ load("jstests/aggregation/extras/utils.js");
{_id: 1, a: null, "same": [{_id: 1, b: null}, {_id: 2}]},
{_id: 2, "same": [{_id: 1, b: null}, {_id: 2}]}
];
- testPipeline([{
- $lookup: {localField: "nonexistent", foreignField: "b", from: "from", as: "same"}
- }],
- expectedResults,
- coll);
+ testPipeline(
+ [{$lookup: {localField: "nonexistent", foreignField: "b", from: "from", as: "same"}}],
+ expectedResults,
+ coll);
// If foreignField is nonexistent, it is treated as if it is null.
expectedResults = [
@@ -67,25 +66,22 @@ load("jstests/aggregation/extras/utils.js");
{_id: 1, a: null, "same": [{_id: 0, b: 1}, {_id: 1, b: null}, {_id: 2}]},
{_id: 2, "same": [{_id: 0, b: 1}, {_id: 1, b: null}, {_id: 2}]}
];
- testPipeline([{
- $lookup: {localField: "a", foreignField: "nonexistent", from: "from", as: "same"}
- }],
- expectedResults,
- coll);
+ testPipeline(
+ [{$lookup: {localField: "a", foreignField: "nonexistent", from: "from", as: "same"}}],
+ expectedResults,
+ coll);
// If there are no matches or the from coll doesn't exist, the result is an empty array.
expectedResults =
[{_id: 0, a: 1, "same": []}, {_id: 1, a: null, "same": []}, {_id: 2, "same": []}];
- testPipeline([{
- $lookup: {localField: "_id", foreignField: "nonexistent", from: "from", as: "same"}
- }],
- expectedResults,
- coll);
- testPipeline([{
- $lookup: {localField: "a", foreignField: "b", from: "nonexistent", as: "same"}
- }],
- expectedResults,
- coll);
+ testPipeline(
+ [{$lookup: {localField: "_id", foreignField: "nonexistent", from: "from", as: "same"}}],
+ expectedResults,
+ coll);
+ testPipeline(
+ [{$lookup: {localField: "a", foreignField: "b", from: "nonexistent", as: "same"}}],
+ expectedResults,
+ coll);
// If field name specified by "as" already exists, it is overwritten.
expectedResults = [
@@ -106,13 +102,14 @@ load("jstests/aggregation/extras/utils.js");
},
{_id: 2, "c": [{_id: 1, b: null}, {_id: 2}], "d": [{_id: 1, b: null}, {_id: 2}]}
];
- testPipeline([
- {$lookup: {localField: "a", foreignField: "b", from: "from", as: "c"}},
- {$project: {"a": 1, "c": 1}},
- {$lookup: {localField: "a", foreignField: "b", from: "from", as: "d"}}
- ],
- expectedResults,
- coll);
+ testPipeline(
+ [
+ {$lookup: {localField: "a", foreignField: "b", from: "from", as: "c"}},
+ {$project: {"a": 1, "c": 1}},
+ {$lookup: {localField: "a", foreignField: "b", from: "from", as: "d"}}
+ ],
+ expectedResults,
+ coll);
//
// Coalescing with $unwind.
@@ -126,12 +123,13 @@ load("jstests/aggregation/extras/utils.js");
{_id: 2, same: {_id: 1, b: null}},
{_id: 2, same: {_id: 2}}
];
- testPipeline([
- {$lookup: {localField: "a", foreignField: "b", from: "from", as: "same"}},
- {$unwind: {path: "$same"}}
- ],
- expectedResults,
- coll);
+ testPipeline(
+ [
+ {$lookup: {localField: "a", foreignField: "b", from: "from", as: "same"}},
+ {$unwind: {path: "$same"}}
+ ],
+ expectedResults,
+ coll);
// An $unwind on the "as" field, with includeArrayIndex.
expectedResults = [
@@ -141,39 +139,51 @@ load("jstests/aggregation/extras/utils.js");
{_id: 2, same: {_id: 1, b: null}, index: NumberLong(0)},
{_id: 2, same: {_id: 2}, index: NumberLong(1)},
];
- testPipeline([
- {$lookup: {localField: "a", foreignField: "b", from: "from", as: "same"}},
- {$unwind: {path: "$same", includeArrayIndex: "index"}}
- ],
- expectedResults,
- coll);
+ testPipeline(
+ [
+ {$lookup: {localField: "a", foreignField: "b", from: "from", as: "same"}},
+ {$unwind: {path: "$same", includeArrayIndex: "index"}}
+ ],
+ expectedResults,
+ coll);
// Normal $unwind with no matching documents.
expectedResults = [];
- testPipeline([
- {$lookup: {localField: "_id", foreignField: "nonexistent", from: "from", as: "same"}},
- {$unwind: {path: "$same"}}
- ],
- expectedResults,
- coll);
+ testPipeline(
+ [
+ {$lookup: {localField: "_id", foreignField: "nonexistent", from: "from", as: "same"}},
+ {$unwind: {path: "$same"}}
+ ],
+ expectedResults,
+ coll);
// $unwind with preserveNullAndEmptyArray with no matching documents.
- expectedResults = [{_id: 0, a: 1}, {_id: 1, a: null}, {_id: 2}, ];
- testPipeline([
- {$lookup: {localField: "_id", foreignField: "nonexistent", from: "from", as: "same"}},
- {$unwind: {path: "$same", preserveNullAndEmptyArrays: true}}
- ],
- expectedResults,
- coll);
+ expectedResults = [
+ {_id: 0, a: 1},
+ {_id: 1, a: null},
+ {_id: 2},
+ ];
+ testPipeline(
+ [
+ {$lookup: {localField: "_id", foreignField: "nonexistent", from: "from", as: "same"}},
+ {$unwind: {path: "$same", preserveNullAndEmptyArrays: true}}
+ ],
+ expectedResults,
+ coll);
// $unwind with preserveNullAndEmptyArray, some with matching documents, some without.
- expectedResults = [{_id: 0, a: 1}, {_id: 1, a: null, same: {_id: 0, b: 1}}, {_id: 2}, ];
- testPipeline([
- {$lookup: {localField: "_id", foreignField: "b", from: "from", as: "same"}},
- {$unwind: {path: "$same", preserveNullAndEmptyArrays: true}}
- ],
- expectedResults,
- coll);
+ expectedResults = [
+ {_id: 0, a: 1},
+ {_id: 1, a: null, same: {_id: 0, b: 1}},
+ {_id: 2},
+ ];
+ testPipeline(
+ [
+ {$lookup: {localField: "_id", foreignField: "b", from: "from", as: "same"}},
+ {$unwind: {path: "$same", preserveNullAndEmptyArrays: true}}
+ ],
+ expectedResults,
+ coll);
// $unwind with preserveNullAndEmptyArray and includeArrayIndex, some with matching
// documents, some without.
@@ -182,15 +192,16 @@ load("jstests/aggregation/extras/utils.js");
{_id: 1, a: null, same: {_id: 0, b: 1}, index: NumberLong(0)},
{_id: 2, index: null},
];
- testPipeline([
- {$lookup: {localField: "_id", foreignField: "b", from: "from", as: "same"}},
- {
- $unwind:
- {path: "$same", preserveNullAndEmptyArrays: true, includeArrayIndex: "index"}
- }
- ],
- expectedResults,
- coll);
+ testPipeline(
+ [
+ {$lookup: {localField: "_id", foreignField: "b", from: "from", as: "same"}},
+ {
+ $unwind:
+ {path: "$same", preserveNullAndEmptyArrays: true, includeArrayIndex: "index"}
+ }
+ ],
+ expectedResults,
+ coll);
//
// Dependencies.
@@ -203,12 +214,13 @@ load("jstests/aggregation/extras/utils.js");
{_id: 1, "same": [{_id: 1, b: null}, {_id: 2}]},
{_id: 2, "same": [{_id: 1, b: null}, {_id: 2}]}
];
- testPipeline([
- {$lookup: {localField: "a", foreignField: "b", from: "from", as: "same"}},
- {$project: {"same": 1}}
- ],
- expectedResults,
- coll);
+ testPipeline(
+ [
+ {$lookup: {localField: "a", foreignField: "b", from: "from", as: "same"}},
+ {$project: {"same": 1}}
+ ],
+ expectedResults,
+ coll);
//
// Dotted field paths.
@@ -277,12 +289,7 @@ load("jstests/aggregation/extras/utils.js");
}
];
expectedResults = [
- {
- _id: 0,
- a: {b: 1},
- same: {documents: {_id: 0, target: 1}},
- c: {d: {e: NumberLong(0)}}
- },
+ {_id: 0, a: {b: 1}, same: {documents: {_id: 0, target: 1}}, c: {d: {e: NumberLong(0)}}},
{_id: 1, same: {}, c: {d: {e: null}}},
];
testPipeline(pipeline, expectedResults, coll);
@@ -401,9 +408,8 @@ load("jstests/aggregation/extras/utils.js");
// An error is thrown if the from collection is sharded.
assert(sharded.adminCommand({shardCollection: "test.from", key: {_id: 1}}));
- assertErrorCode(
- sharded.getDB('test').lookUp,
- [{$lookup: {localField: "a", foreignField: "b", from: "from", as: "same"}}],
- 28769);
+ assertErrorCode(sharded.getDB('test').lookUp,
+ [{$lookup: {localField: "a", foreignField: "b", from: "from", as: "same"}}],
+ 28769);
sharded.stop();
}());
diff --git a/jstests/aggregation/bugs/server20163.js b/jstests/aggregation/bugs/server20163.js
index 501a6cc546a..e61ba606c24 100644
--- a/jstests/aggregation/bugs/server20163.js
+++ b/jstests/aggregation/bugs/server20163.js
@@ -12,182 +12,127 @@ load("jstests/aggregation/extras/utils.js"); // For assertErrorCode.
var zipObj = 3;
assertErrorCode(coll,
- [{$project: {zipped: {$zip: zipObj}}}],
+ [{$project: {zipped: {$zip: zipObj}}}],
34460,
"$zip requires an object" + " as an argument.");
- zipObj = {
- inputs: []
- };
+ zipObj = {inputs: []};
assertErrorCode(coll,
- [{$project: {zipped: {$zip: zipObj}}}],
+ [{$project: {zipped: {$zip: zipObj}}}],
34465,
"$zip requires at least" + " one input array");
- zipObj = {
- inputs: {"a": "b"}
- };
+ zipObj = {inputs: {"a": "b"}};
assertErrorCode(coll, [{$project: {zipped: {$zip: zipObj}}}], 34461, "inputs is not an array");
- zipObj = {
- inputs: ["$a"],
- defaults: ["A"]
- };
+ zipObj = {inputs: ["$a"], defaults: ["A"]};
assertErrorCode(coll,
- [{$project: {zipped: {$zip: zipObj}}}],
+ [{$project: {zipped: {$zip: zipObj}}}],
34466,
"cannot specify defaults" + " unless useLongestLength is true.");
- zipObj = {
- inputs: ["$a"],
- defaults: ["A", "B"],
- useLongestLength: true
- };
+ zipObj = {inputs: ["$a"], defaults: ["A", "B"], useLongestLength: true};
assertErrorCode(coll,
- [{$project: {zipped: {$zip: zipObj}}}],
+ [{$project: {zipped: {$zip: zipObj}}}],
34467,
"inputs and defaults" + " must be the same length.");
- zipObj = {
- inputs: ["$a"],
- defaults: {"a": "b"}
- };
+ zipObj = {inputs: ["$a"], defaults: {"a": "b"}};
assertErrorCode(
coll, [{$project: {zipped: {$zip: zipObj}}}], 34462, "defaults is not an" + " array");
- zipObj = {
- inputs: ["$a"],
- defaults: ["A"],
- useLongestLength: 1
- };
+ zipObj = {inputs: ["$a"], defaults: ["A"], useLongestLength: 1};
assertErrorCode(
coll, [{$project: {zipped: {$zip: zipObj}}}], 34463, "useLongestLength is not" + " a bool");
- zipObj = {
- inputs: ["$a", "$b"],
- defaults: ["A"],
- notAField: 1
- };
+ zipObj = {inputs: ["$a", "$b"], defaults: ["A"], notAField: 1};
assertErrorCode(coll, [{$project: {zipped: {$zip: zipObj}}}], 34464, "unknown argument");
- zipObj = {
- inputs: ["A", "B"]
- };
+ zipObj = {inputs: ["A", "B"]};
assertErrorCode(coll,
- [{$project: {zipped: {$zip: zipObj}}}],
+ [{$project: {zipped: {$zip: zipObj}}}],
34468,
"an element of inputs" + " was not an array.");
- zipObj = {
- inputs: [[1, 2, 3], ["A", "B", "C"]]
- };
+ zipObj = {inputs: [[1, 2, 3], ["A", "B", "C"]]};
var res = coll.aggregate([{$project: {zipped: {$zip: zipObj}}}]);
var output = res.toArray();
assert.eq(1, output.length);
assert.eq(output[0].zipped, [[1, "A"], [2, "B"], [3, "C"]]);
- zipObj = {
- inputs: [[1, 2, 3], null]
- };
+ zipObj = {inputs: [[1, 2, 3], null]};
res = coll.aggregate([{$project: {zipped: {$zip: zipObj}}}]);
output = res.toArray();
assert.eq(1, output.length);
assert.eq(output[0].zipped, null);
- zipObj = {
- inputs: [null, [1, 2, 3]]
- };
+ zipObj = {inputs: [null, [1, 2, 3]]};
res = coll.aggregate([{$project: {zipped: {$zip: zipObj}}}]);
output = res.toArray();
assert.eq(1, output.length);
assert.eq(output[0].zipped, null);
- zipObj = {
- inputs: ["$missing", [1, 2, 3]]
- };
+ zipObj = {inputs: ["$missing", [1, 2, 3]]};
res = coll.aggregate([{$project: {zipped: {$zip: zipObj}}}]);
output = res.toArray();
assert.eq(1, output.length);
assert.eq(output[0].zipped, null);
- zipObj = {
- inputs: [undefined, [1, 2, 3]]
- };
+ zipObj = {inputs: [undefined, [1, 2, 3]]};
res = coll.aggregate([{$project: {zipped: {$zip: zipObj}}}]);
output = res.toArray();
assert.eq(1, output.length);
assert.eq(output[0].zipped, null);
- zipObj = {
- inputs: [[1, 2, 3], ["A", "B"]]
- };
+ zipObj = {inputs: [[1, 2, 3], ["A", "B"]]};
res = coll.aggregate([{$project: {zipped: {$zip: zipObj}}}]);
output = res.toArray();
assert.eq(1, output.length);
assert.eq(output[0].zipped, [[1, "A"], [2, "B"]]);
- zipObj = {
- inputs: [["A", "B"], [1, 2, 3]]
- };
+ zipObj = {inputs: [["A", "B"], [1, 2, 3]]};
res = coll.aggregate([{$project: {zipped: {$zip: zipObj}}}]);
output = res.toArray();
assert.eq(1, output.length);
assert.eq(output[0].zipped, [["A", 1], ["B", 2]]);
- zipObj = {
- inputs: [[], []]
- };
+ zipObj = {inputs: [[], []]};
res = coll.aggregate([{$project: {zipped: {$zip: zipObj}}}]);
output = res.toArray();
assert.eq(1, output.length);
assert.eq(output[0].zipped, []);
- zipObj = {
- inputs: [["$short"], ["$long"]]
- };
+ zipObj = {inputs: [["$short"], ["$long"]]};
res = coll.aggregate([{$project: {zipped: {$zip: zipObj}}}]);
output = res.toArray();
assert.eq(1, output.length);
assert.eq(output[0].zipped, [[['x', 'y'], [1, 2, 3]]]);
- zipObj = {
- inputs: ["$short", "$long"]
- };
+ zipObj = {inputs: ["$short", "$long"]};
res = coll.aggregate([{$project: {zipped: {$zip: zipObj}}}]);
output = res.toArray();
assert.eq(1, output.length);
assert.eq(output[0].zipped, [['x', 1], ['y', 2]]);
- zipObj = {
- inputs: [["$long"]]
- };
+ zipObj = {inputs: [["$long"]]};
res = coll.aggregate([{$project: {zipped: {$zip: zipObj}}}]);
output = res.toArray();
assert.eq(1, output.length);
assert.eq(output[0].zipped, [[[1, 2, 3]]]);
- zipObj = {
- inputs: [[1, 2, 3], ['a', 'b', 'c'], ['c', 'b', 'a']]
- };
+ zipObj = {inputs: [[1, 2, 3], ['a', 'b', 'c'], ['c', 'b', 'a']]};
res = coll.aggregate([{$project: {zipped: {$zip: zipObj}}}]);
output = res.toArray();
assert.eq(1, output.length);
assert.eq(output[0].zipped, [[1, 'a', 'c'], [2, 'b', 'b'], [3, 'c', 'a']]);
- zipObj = {
- inputs: [[1, 2, 3], ["A", "B"]],
- defaults: ["C", "D"],
- useLongestLength: true
- };
+ zipObj = {inputs: [[1, 2, 3], ["A", "B"]], defaults: ["C", "D"], useLongestLength: true};
res = coll.aggregate([{$project: {zipped: {$zip: zipObj}}}]);
output = res.toArray();
assert.eq(1, output.length);
assert.eq(output[0].zipped, [[1, "A"], [2, "B"], [3, "D"]]);
- zipObj = {
- inputs: [[1, 2, 3], ["A", "B"]],
- useLongestLength: true
- };
+ zipObj = {inputs: [[1, 2, 3], ["A", "B"]], useLongestLength: true};
res = coll.aggregate([{$project: {zipped: {$zip: zipObj}}}]);
output = res.toArray();
assert.eq(1, output.length);
diff --git a/jstests/aggregation/bugs/server20169.js b/jstests/aggregation/bugs/server20169.js
index f4d8735701e..27995b8030c 100644
--- a/jstests/aggregation/bugs/server20169.js
+++ b/jstests/aggregation/bugs/server20169.js
@@ -13,49 +13,49 @@ load("jstests/aggregation/extras/utils.js"); // For assertErrorCode.
var rangeObj = [1];
assertErrorCode(coll,
- [{$project: {range: {$range: rangeObj}}}],
+ [{$project: {range: {$range: rangeObj}}}],
28667,
"range requires two" + " or three arguments");
rangeObj = ["a", 1];
assertErrorCode(coll,
- [{$project: {range: {$range: rangeObj}}}],
+ [{$project: {range: {$range: rangeObj}}}],
34443,
"range requires a" + " numeric starting value");
rangeObj = [1.1, 1];
assertErrorCode(coll,
- [{$project: {range: {$range: rangeObj}}}],
+ [{$project: {range: {$range: rangeObj}}}],
34444,
"range requires an" + " integral starting value");
rangeObj = [1, "a"];
assertErrorCode(coll,
- [{$project: {range: {$range: rangeObj}}}],
+ [{$project: {range: {$range: rangeObj}}}],
34445,
"range requires a" + " numeric ending value");
rangeObj = [1, 1.1];
assertErrorCode(coll,
- [{$project: {range: {$range: rangeObj}}}],
+ [{$project: {range: {$range: rangeObj}}}],
34446,
"range requires an" + " integral ending value");
rangeObj = [1, 3, "a"];
assertErrorCode(coll,
- [{$project: {range: {$range: rangeObj}}}],
+ [{$project: {range: {$range: rangeObj}}}],
34447,
"range requires a" + " numeric step value");
rangeObj = [1, 3, 1.1];
assertErrorCode(coll,
- [{$project: {range: {$range: rangeObj}}}],
+ [{$project: {range: {$range: rangeObj}}}],
34448,
"range requires an" + " integral step value");
rangeObj = [1, 3, 0];
assertErrorCode(coll,
- [{$project: {range: {$range: rangeObj}}}],
+ [{$project: {range: {$range: rangeObj}}}],
34449,
"range requires a" + " non-zero step value");
}());
diff --git a/jstests/aggregation/bugs/server21632.js b/jstests/aggregation/bugs/server21632.js
index 5aa9a315b5f..c99834c6f73 100644
--- a/jstests/aggregation/bugs/server21632.js
+++ b/jstests/aggregation/bugs/server21632.js
@@ -35,10 +35,7 @@
// If there is only one document, we should get that document.
var paddingStr = "abcdefghijklmnopqrstuvwxyz";
- var firstDoc = {
- _id: 0,
- paddingStr: paddingStr
- };
+ var firstDoc = {_id: 0, paddingStr: paddingStr};
assert.writeOK(coll.insert(firstDoc));
assert.eq([firstDoc], coll.aggregate([{$sample: {size: 1}}]).toArray());
assert.eq([firstDoc], coll.aggregate([{$sample: {size: 10}}]).toArray());
diff --git a/jstests/aggregation/bugs/server22093.js b/jstests/aggregation/bugs/server22093.js
index aca39a4e789..61302bbf4cd 100644
--- a/jstests/aggregation/bugs/server22093.js
+++ b/jstests/aggregation/bugs/server22093.js
@@ -22,9 +22,8 @@ load('jstests/libs/analyze_plan.js');
assert.eq(simpleGroup.length, 1);
assert.eq(simpleGroup[0]["count"], 15);
- var explained =
- coll.explain()
- .aggregate([{$match: {foo: {$gt: 0}}}, {$group: {_id: null, count: {$sum: 1}}}]);
+ var explained = coll.explain().aggregate(
+ [{$match: {foo: {$gt: 0}}}, {$group: {_id: null, count: {$sum: 1}}}]);
assert(planHasStage(explained.stages[0].$cursor.queryPlanner.winningPlan, "COUNT_SCAN"));
diff --git a/jstests/aggregation/bugs/server22580.js b/jstests/aggregation/bugs/server22580.js
index afbfdd00dcd..3a448173875 100644
--- a/jstests/aggregation/bugs/server22580.js
+++ b/jstests/aggregation/bugs/server22580.js
@@ -12,32 +12,32 @@ load("jstests/aggregation/extras/utils.js"); // For assertErrorCode.
coll.insert({});
assertErrorCode(coll,
- [{$project: {substr: {$substrCP: ["abc", 0, "a"]}}}],
+ [{$project: {substr: {$substrCP: ["abc", 0, "a"]}}}],
34452,
"$substrCP" + " does not accept non-numeric types as a length.");
assertErrorCode(coll,
- [{$project: {substr: {$substrCP: ["abc", 0, NaN]}}}],
+ [{$project: {substr: {$substrCP: ["abc", 0, NaN]}}}],
34453,
"$substrCP" + " does not accept non-integers as a length.");
assertErrorCode(coll,
- [{$project: {substr: {$substrCP: ["abc", "abc", 3]}}}],
+ [{$project: {substr: {$substrCP: ["abc", "abc", 3]}}}],
34450,
"$substrCP does not accept non-numeric types as a starting index.");
assertErrorCode(coll,
- [{$project: {substr: {$substrCP: ["abc", 2.2, 3]}}}],
+ [{$project: {substr: {$substrCP: ["abc", 2.2, 3]}}}],
34451,
"$substrCP" + " does not accept non-integers as a starting index.");
assertErrorCode(coll,
- [{$project: {substr: {$substrCP: ["abc", -1, 3]}}}],
+ [{$project: {substr: {$substrCP: ["abc", -1, 3]}}}],
34455,
"$substrCP " + "does not accept negative integers as inputs.");
assertErrorCode(coll,
- [{$project: {substr: {$substrCP: ["abc", 1, -3]}}}],
+ [{$project: {substr: {$substrCP: ["abc", 1, -3]}}}],
34454,
"$substrCP " + "does not accept negative integers as inputs.");
}());
diff --git a/jstests/aggregation/bugs/server3253.js b/jstests/aggregation/bugs/server3253.js
index 1adab9ca977..774712ecb2f 100644
--- a/jstests/aggregation/bugs/server3253.js
+++ b/jstests/aggregation/bugs/server3253.js
@@ -58,7 +58,7 @@ assert.eq([], listCollections(/tmp\.agg_out/));
// basic test
test(input,
- [{$project: {a: {$add: ['$_id', '$_id']}}}],
+ [{$project: {a: {$add: ['$_id', '$_id']}}}],
[{_id: 1, a: 2}, {_id: 2, a: 4}, {_id: 3, a: 6}]);
// test with indexes
@@ -66,7 +66,7 @@ assert.eq(output.getIndexes().length, 1);
output.ensureIndex({a: 1});
assert.eq(output.getIndexes().length, 2);
test(input,
- [{$project: {a: {$multiply: ['$_id', '$_id']}}}],
+ [{$project: {a: {$multiply: ['$_id', '$_id']}}}],
[{_id: 1, a: 1}, {_id: 2, a: 4}, {_id: 3, a: 9}]);
// test with empty result set and make sure old result is gone, but indexes remain
@@ -81,13 +81,11 @@ test(input, [{$project: {b: "$_id"}}], [{_id: 1, b: 1}, {_id: 2, b: 2}, {_id: 3,
// test with full text index
output.ensureIndex({c: "text"});
assert.eq(output.getIndexes().length, 4);
-test(input,
- [{$project: {c: {$concat: ["hello there ", "_id"]}}}],
- [
- {_id: 1, c: "hello there _id"},
- {_id: 2, c: "hello there _id"},
- {_id: 3, c: "hello there _id"}
- ]);
+test(input, [{$project: {c: {$concat: ["hello there ", "_id"]}}}], [
+ {_id: 1, c: "hello there _id"},
+ {_id: 2, c: "hello there _id"},
+ {_id: 3, c: "hello there _id"}
+]);
// test with capped collection
cappedOutput.drop();
diff --git a/jstests/aggregation/bugs/server4588.js b/jstests/aggregation/bugs/server4588.js
index ba49c78e9ea..49f41283f6d 100644
--- a/jstests/aggregation/bugs/server4588.js
+++ b/jstests/aggregation/bugs/server4588.js
@@ -13,7 +13,12 @@
// Without includeArrayIndex.
var actualResults = coll.aggregate([{$unwind: {path: "$x"}}]).toArray();
- var expectedResults = [{_id: 3, x: 1}, {_id: 3, x: 2}, {_id: 3, x: 3}, {_id: 4, x: 5}, ];
+ var expectedResults = [
+ {_id: 3, x: 1},
+ {_id: 3, x: 2},
+ {_id: 3, x: 3},
+ {_id: 4, x: 5},
+ ];
assert.eq(expectedResults, actualResults, "Incorrect results for normal $unwind");
// With includeArrayIndex, index inserted into a new field.
@@ -28,9 +33,12 @@
// With both includeArrayIndex and preserveNullAndEmptyArrays.
// TODO: update this test when SERVER-20168 is resolved.
- actualResults = coll.aggregate([{
- $unwind: {path: "$x", includeArrayIndex: "index", preserveNullAndEmptyArrays: true}
- }]).toArray();
+ actualResults =
+ coll.aggregate([{
+ $unwind:
+ {path: "$x", includeArrayIndex: "index", preserveNullAndEmptyArrays: true}
+ }])
+ .toArray();
expectedResults = [
{_id: 0, index: null},
{_id: 1, x: null, index: null},
diff --git a/jstests/aggregation/bugs/server5044.js b/jstests/aggregation/bugs/server5044.js
index 945f31c302c..f1f77a1991d 100644
--- a/jstests/aggregation/bugs/server5044.js
+++ b/jstests/aggregation/bugs/server5044.js
@@ -10,12 +10,12 @@ function test(data, popExpected, sampExpected) {
assert.writeOK(t.insert({num: data[i]}));
var res = t.aggregate({
- $group: {
- _id: 1,
- pop: {$stdDevPop: '$num'},
- samp: {$stdDevSamp: '$num'},
- }
- }).next();
+ $group: {
+ _id: 1,
+ pop: {$stdDevPop: '$num'},
+ samp: {$stdDevSamp: '$num'},
+ }
+ }).next();
if (popExpected === null) {
assert.isnull(res.pop);
diff --git a/jstests/aggregation/bugs/server6121.js b/jstests/aggregation/bugs/server6121.js
index 97d5a4d72c9..b7ea33abdaa 100644
--- a/jstests/aggregation/bugs/server6121.js
+++ b/jstests/aggregation/bugs/server6121.js
@@ -22,20 +22,22 @@ db.s6121.drop();
db.s6121.save({date: new Timestamp(1341337661, 1)});
db.s6121.save({date: new Date(1341337661000)});
// Aggregate checking various combinations of the constant and the field
-var s6121 = db.s6121.aggregate({
- $project: {
- _id: 0,
- dayOfMonth: {$dayOfMonth: '$date'},
- dayOfWeek: {$dayOfWeek: '$date'},
- dayOfYear: {$dayOfYear: '$date'},
- hour: {$hour: '$date'},
- minute: {$minute: '$date'},
- month: {$month: '$date'},
- second: {$second: '$date'},
- week: {$week: '$date'},
- year: {$year: '$date'}
- }
-}).toArray();
+var s6121 = db.s6121
+ .aggregate({
+ $project: {
+ _id: 0,
+ dayOfMonth: {$dayOfMonth: '$date'},
+ dayOfWeek: {$dayOfWeek: '$date'},
+ dayOfYear: {$dayOfYear: '$date'},
+ hour: {$hour: '$date'},
+ minute: {$minute: '$date'},
+ month: {$month: '$date'},
+ second: {$second: '$date'},
+ week: {$week: '$date'},
+ year: {$year: '$date'}
+ }
+ })
+ .toArray();
// Assert the two entries are equal
assert.eq(s6121[0], s6121[1], 's6121 failed');
diff --git a/jstests/aggregation/bugs/server6125.js b/jstests/aggregation/bugs/server6125.js
index 746c191d8fe..bfc4f471318 100644
--- a/jstests/aggregation/bugs/server6125.js
+++ b/jstests/aggregation/bugs/server6125.js
@@ -10,9 +10,7 @@
// to make results array nested (problem 2)
function nestArray(nstArray) {
for (x = 0; x < nstArray.length; x++) {
- nstArray[x].a = {
- b: nstArray[x].a
- };
+ nstArray[x].a = {b: nstArray[x].a};
}
}
diff --git a/jstests/aggregation/bugs/server6131.js b/jstests/aggregation/bugs/server6131.js
index 602894ab721..640eea2723e 100644
--- a/jstests/aggregation/bugs/server6131.js
+++ b/jstests/aggregation/bugs/server6131.js
@@ -11,11 +11,7 @@ t.drop();
// An empty array document is dropped.
t.save({_id: 0, a: 1, b: [], c: 2});
-assertAggregationResults([],
- {
-$unwind:
- '$b'
- });
+assertAggregationResults([], {$unwind: '$b'});
// Values from a nonempty array in another document are unwound.
t.save({_id: 1, b: [4, 5]});
@@ -29,48 +25,28 @@ t.drop();
// A nested empty array document is dropped.
t.save({_id: 0, a: 1, b: {x: 10, y: [], z: 20}, c: 2});
-assertAggregationResults([],
- {
-$unwind:
- '$b.y'
- });
+assertAggregationResults([], {$unwind: '$b.y'});
t.drop();
// A null value document is dropped.
t.save({_id: 0, a: 1, b: null, c: 2});
-assertAggregationResults([],
- {
-$unwind:
- '$b'
- });
+assertAggregationResults([], {$unwind: '$b'});
t.drop();
// A missing value causes the document to be dropped.
t.save({_id: 0, a: 1, c: 2});
-assertAggregationResults([],
- {
-$unwind:
- '$b'
- });
+assertAggregationResults([], {$unwind: '$b'});
t.drop();
// A missing value in an existing nested object causes the document to be dropped.
t.save({_id: 0, a: 1, b: {d: 4}, c: 2});
-assertAggregationResults([],
- {
-$unwind:
- '$b.y'
- });
+assertAggregationResults([], {$unwind: '$b.y'});
t.drop();
// A missing value in a missing nested object causes the document to be dropped.
t.save({_id: 0, a: 1, b: 10, c: 2});
-assertAggregationResults([],
- {
-$unwind:
- '$b.y'
- });
+assertAggregationResults([], {$unwind: '$b.y'});
diff --git a/jstests/aggregation/bugs/server6179.js b/jstests/aggregation/bugs/server6179.js
index 20158af7fb7..c05103a13b8 100644
--- a/jstests/aggregation/bugs/server6179.js
+++ b/jstests/aggregation/bugs/server6179.js
@@ -28,9 +28,11 @@
{movechunk: "test.data", find: {_id: 50}, to: s.getOther(s.getPrimaryShard("test")).name});
// Check that we get results rather than an error
- var result = d.data.aggregate({$group: {_id: '$_id', i: {$first: '$i'}}},
- {$group: {_id: '$i', avg_id: {$avg: '$_id'}}},
- {$sort: {_id: 1}}).toArray();
+ var result = d.data
+ .aggregate({$group: {_id: '$_id', i: {$first: '$i'}}},
+ {$group: {_id: '$i', avg_id: {$avg: '$_id'}}},
+ {$sort: {_id: 1}})
+ .toArray();
expected = [
{"_id": 0, "avg_id": 45},
{"_id": 1, "avg_id": 46},
diff --git a/jstests/aggregation/bugs/server6189.js b/jstests/aggregation/bugs/server6189.js
index 4cb615f0659..f8cb88194e2 100644
--- a/jstests/aggregation/bugs/server6189.js
+++ b/jstests/aggregation/bugs/server6189.js
@@ -11,36 +11,35 @@ function test(date, testSynthetics) {
: 'ISODate("%Y-%m-%dT%H:%M:%S.%LZ")';
// Can't use aggregate helper or assertErrorCode because we need to handle multiple error types
- var res = c.runCommand('aggregate',
- {
- pipeline: [{
- $project: {
- _id: 0,
- year: {$year: '$date'},
- month: {$month: '$date'},
- dayOfMonth: {$dayOfMonth: '$date'},
- hour: {$hour: '$date'},
- minute: {$minute: '$date'},
- second: {$second: '$date'}
-
- // server-6666
- ,
- millisecond: {$millisecond: '$date'}
-
- // server-9289
- ,
- millisecondPlusTen: {$millisecond: {$add: ['$date', 10]}}
-
- // $substr will call coerceToString
- ,
- string: {$substr: ['$date', 0, 1000]}
-
- // server-11118
- ,
- format: {$dateToString: {format: ISOfmt, date: '$date'}}
- }
- }]
- });
+ var res = c.runCommand('aggregate', {
+ pipeline: [{
+ $project: {
+ _id: 0,
+ year: {$year: '$date'},
+ month: {$month: '$date'},
+ dayOfMonth: {$dayOfMonth: '$date'},
+ hour: {$hour: '$date'},
+ minute: {$minute: '$date'},
+ second: {$second: '$date'}
+
+ // server-6666
+ ,
+ millisecond: {$millisecond: '$date'}
+
+ // server-9289
+ ,
+ millisecondPlusTen: {$millisecond: {$add: ['$date', 10]}}
+
+ // $substr will call coerceToString
+ ,
+ string: {$substr: ['$date', 0, 1000]}
+
+ // server-11118
+ ,
+ format: {$dateToString: {format: ISOfmt, date: '$date'}}
+ }
+ }]
+ });
if (date.valueOf() < 0 && _isWindows() && res.code == 16422) {
// some versions of windows (but not all) fail with dates before 1970
@@ -55,20 +54,19 @@ function test(date, testSynthetics) {
}
assert.commandWorked(res);
- assert.eq(res.result[0],
- {
- year: date.getUTCFullYear(),
- month: date.getUTCMonth() + 1 // jan == 1
- ,
- dayOfMonth: date.getUTCDate(),
- hour: date.getUTCHours(),
- minute: date.getUTCMinutes(),
- second: date.getUTCSeconds(),
- millisecond: date.getUTCMilliseconds(),
- millisecondPlusTen: ((date.getUTCMilliseconds() + 10) % 1000),
- string: date.tojson().slice(9, 28),
- format: date.tojson()
- });
+ assert.eq(res.result[0], {
+ year: date.getUTCFullYear(),
+ month: date.getUTCMonth() + 1 // jan == 1
+ ,
+ dayOfMonth: date.getUTCDate(),
+ hour: date.getUTCHours(),
+ minute: date.getUTCMinutes(),
+ second: date.getUTCSeconds(),
+ millisecond: date.getUTCMilliseconds(),
+ millisecondPlusTen: ((date.getUTCMilliseconds() + 10) % 1000),
+ string: date.tojson().slice(9, 28),
+ format: date.tojson()
+ });
if (testSynthetics) {
// Tests with this set all have the same value for these fields
diff --git a/jstests/aggregation/bugs/server6190.js b/jstests/aggregation/bugs/server6190.js
index d32a652e74b..ea7bfe1601b 100644
--- a/jstests/aggregation/bugs/server6190.js
+++ b/jstests/aggregation/bugs/server6190.js
@@ -8,8 +8,9 @@ t.drop();
t.save({});
function week(date) {
- return t.aggregate({$project: {a: {$week: date}}},
- {$match: {a: {$type: 16 /* Int type expected */}}})
+ return t
+ .aggregate({$project: {a: {$week: date}}},
+ {$match: {a: {$type: 16 /* Int type expected */}}})
.toArray()[0]
.a;
}
diff --git a/jstests/aggregation/bugs/server6195.js b/jstests/aggregation/bugs/server6195.js
index cca80a14ad5..13dccd10877 100644
--- a/jstests/aggregation/bugs/server6195.js
+++ b/jstests/aggregation/bugs/server6195.js
@@ -27,7 +27,7 @@ assertErrorCode(c, {$project: {str: {$concat: [1]}}}, 16702);
assertErrorCode(c, {$project: {str: {$concat: [NumberInt(1)]}}}, 16702);
assertErrorCode(c, {$project: {str: {$concat: [NumberLong(1)]}}}, 16702);
assertErrorCode(c, {$project: {str: {$concat: [true]}}}, 16702);
-assertErrorCode(c, {$project: {str: {$concat: [function(){}]}}}, 16702);
+assertErrorCode(c, {$project: {str: {$concat: [function() {}]}}}, 16702);
assertErrorCode(c, {$project: {str: {$concat: [{}]}}}, 16702);
assertErrorCode(c, {$project: {str: {$concat: [[]]}}}, 16702);
assertErrorCode(c, {$project: {str: {$concat: [new Timestamp(0, 0)]}}}, 16702);
diff --git a/jstests/aggregation/bugs/server6529.js b/jstests/aggregation/bugs/server6529.js
index 1bc4119c547..94af2f1fc72 100644
--- a/jstests/aggregation/bugs/server6529.js
+++ b/jstests/aggregation/bugs/server6529.js
@@ -13,16 +13,16 @@ assertErrorCode(c, {$group: {_id: {a: 1}}}, 17390);
// but any amount of nesting in a project should work
assert.eq(c.aggregate({$project: {_id: 0, a: {b: {c: {d: {e: {f: {g: 1}}}}}}}}).toArray(),
- [{a: {b: {c: {d: {e: {f: {g: 19}}}}}}}]);
+ [{a: {b: {c: {d: {e: {f: {g: 19}}}}}}}]);
assert.eq(c.aggregate({$project: {_id: 0, a: {b: {c: {d: {e: {f: 1}}}}}}}).toArray(),
- [{a: {b: {c: {d: {e: {f: {g: 19}}}}}}}]);
+ [{a: {b: {c: {d: {e: {f: {g: 19}}}}}}}]);
assert.eq(c.aggregate({$project: {_id: 0, a: {b: {c: {d: {e: 1}}}}}}).toArray(),
- [{a: {b: {c: {d: {e: {f: {g: 19}}}}}}}]);
+ [{a: {b: {c: {d: {e: {f: {g: 19}}}}}}}]);
assert.eq(c.aggregate({$project: {_id: 0, a: {b: {c: {d: 1}}}}}).toArray(),
- [{a: {b: {c: {d: {e: {f: {g: 19}}}}}}}]);
+ [{a: {b: {c: {d: {e: {f: {g: 19}}}}}}}]);
assert.eq(c.aggregate({$project: {_id: 0, a: {b: {c: 1}}}}).toArray(),
- [{a: {b: {c: {d: {e: {f: {g: 19}}}}}}}]);
+ [{a: {b: {c: {d: {e: {f: {g: 19}}}}}}}]);
assert.eq(c.aggregate({$project: {_id: 0, a: {b: 1}}}).toArray(),
- [{a: {b: {c: {d: {e: {f: {g: 19}}}}}}}]);
+ [{a: {b: {c: {d: {e: {f: {g: 19}}}}}}}]);
assert.eq(c.aggregate({$project: {_id: 0, a: 1}}).toArray(),
- [{a: {b: {c: {d: {e: {f: {g: 19}}}}}}}]);
+ [{a: {b: {c: {d: {e: {f: {g: 19}}}}}}}]);
diff --git a/jstests/aggregation/bugs/server6531.js b/jstests/aggregation/bugs/server6531.js
index 7d117ce6905..7d020d79219 100644
--- a/jstests/aggregation/bugs/server6531.js
+++ b/jstests/aggregation/bugs/server6531.js
@@ -10,12 +10,8 @@ for (var x = 0; x < 10; x++) {
}
function test(variant) {
- query = {
- loc: {$within: {$center: [[5, 5], 3]}}
- };
- sort = {
- _id: 1
- };
+ query = {loc: {$within: {$center: [[5, 5], 3]}}};
+ sort = {_id: 1};
aggOut = c.aggregate({$match: query}, {$sort: sort});
cursor = c.find(query).sort(sort);
diff --git a/jstests/aggregation/bugs/server6556.js b/jstests/aggregation/bugs/server6556.js
index 636bef6b02c..261dc5a35b5 100644
--- a/jstests/aggregation/bugs/server6556.js
+++ b/jstests/aggregation/bugs/server6556.js
@@ -7,17 +7,17 @@ c.save({foo: "as\0df"});
// compare the whole string, they should match
assert.eq(c.aggregate({$project: {_id: 0, matches: {$eq: ["as\0df", "$foo"]}}}).toArray(),
- [{matches: true}]);
+ [{matches: true}]);
// compare with the substring containing only the up to the null, they should not match
assert.eq(c.aggregate({
- $project: {_id: 0, matches: {$eq: ["as\0df", {$substrBytes: ["$foo", 0, 3]}]}}
-}).toArray(),
- [{matches: false}]);
+ $project: {_id: 0, matches: {$eq: ["as\0df", {$substrBytes: ["$foo", 0, 3]}]}}
+ }).toArray(),
+ [{matches: false}]);
// partial the other way shouldnt work either
assert.eq(c.aggregate({$project: {_id: 0, matches: {$eq: ["as", "$foo"]}}}).toArray(),
- [{matches: false}]);
+ [{matches: false}]);
// neither should one that differs after the null
assert.eq(c.aggregate({$project: {_id: 0, matches: {$eq: ["as\0de", "$foo"]}}}).toArray(),
- [{matches: false}]);
+ [{matches: false}]);
// should assert on fieldpaths with a null
assert.throws(c.aggregate, {$project: {_id: 0, matches: {$eq: ["as\0df", "$f\0oo"]}}});
diff --git a/jstests/aggregation/bugs/server7781.js b/jstests/aggregation/bugs/server7781.js
index 230a8a64c9f..0a4831fb800 100644
--- a/jstests/aggregation/bugs/server7781.js
+++ b/jstests/aggregation/bugs/server7781.js
@@ -30,10 +30,7 @@
for (var i = 0; i < cmdOut.length; i++) {
massaged = {};
Object.extend(massaged, cmdOut[i].obj, /*deep=*/true);
- massaged.stats = {
- 'dis': cmdOut[i].dis,
- 'loc': cmdOut[i].loc
- };
+ massaged.stats = {'dis': cmdOut[i].dis, 'loc': cmdOut[i].loc};
if (!friendlyEqual(massaged, aggOut[i])) {
allSame = false; // don't bail yet since we want to print all differences
@@ -87,12 +84,7 @@
// test with defaults
var queryPoint = pointMaker.mkPt(0.25); // stick to center of map
- geoCmd = {
- geoNear: coll,
- near: queryPoint,
- includeLocs: true,
- spherical: true
- };
+ geoCmd = {geoNear: coll, near: queryPoint, includeLocs: true, spherical: true};
aggCmd = {
$geoNear: {
near: queryPoint,
diff --git a/jstests/aggregation/bugs/server9840.js b/jstests/aggregation/bugs/server9840.js
index b3a73cfc3d7..4316730370a 100644
--- a/jstests/aggregation/bugs/server9840.js
+++ b/jstests/aggregation/bugs/server9840.js
@@ -27,62 +27,57 @@ test({$add: ['$two', '$$CURRENT.three']}, 5);
test({$add: ['$$CURRENT.two', '$$ROOT.nested.four']}, 6);
// $let simple
-test({$let: {vars: {a: 10}, in: '$$a'}}, 10);
-test({$let: {vars: {a: '$zero'}, in: '$$a'}}, 0);
-test({$let: {vars: {a: {$add: ['$one', '$two']}, b: 10}, in: {$multiply: ['$$a', '$$b']}}}, 30);
+test({$let: {vars: {a: 10}, in : '$$a'}}, 10);
+test({$let: {vars: {a: '$zero'}, in : '$$a'}}, 0);
+test({$let: {vars: {a: {$add: ['$one', '$two']}, b: 10}, in : {$multiply: ['$$a', '$$b']}}}, 30);
// $let changing CURRENT
-test({$let: {vars: {CURRENT: '$$ROOT.nested'}, in: {$multiply: ['$four', '$$ROOT.two']}}}, 8);
-test(
- {
- $let: {
- vars: {CURRENT: '$$CURRENT.nested'}, // using original value of CURRENT
- in: {$multiply: ['$four', '$$ROOT.two']}
- }
- },
- 8);
-test(
- {
- $let: {
- vars: {CURRENT: '$nested'}, // same as last
- in: {$multiply: ['$four', '$$ROOT.two']}
- }
- },
- 8);
-test(
- {
- $let: {
- vars: {CURRENT: {$const: {ten: 10}}}, // "artificial" object
- in: {$multiply: ['$ten', '$$ROOT.two']}
- }
- },
- 20);
-test(
- {
- $let: {
- vars: {CURRENT: '$three'}, // sets current to the number 3 (not an object)
- in: {$multiply: ['$$CURRENT', '$$ROOT.two']}
- }
- },
- 6);
+test({$let: {vars: {CURRENT: '$$ROOT.nested'}, in : {$multiply: ['$four', '$$ROOT.two']}}}, 8);
+test({
+ $let: {
+ vars: {CURRENT: '$$CURRENT.nested'}, // using original value of CURRENT
+ in : {$multiply: ['$four', '$$ROOT.two']}
+ }
+},
+ 8);
+test({
+ $let: {
+ vars: {CURRENT: '$nested'}, // same as last
+ in : {$multiply: ['$four', '$$ROOT.two']}
+ }
+},
+ 8);
+test({
+ $let: {
+ vars: {CURRENT: {$const: {ten: 10}}}, // "artificial" object
+ in : {$multiply: ['$ten', '$$ROOT.two']}
+ }
+},
+ 20);
+test({
+ $let: {
+ vars: {CURRENT: '$three'}, // sets current to the number 3 (not an object)
+ in : {$multiply: ['$$CURRENT', '$$ROOT.two']}
+ }
+},
+ 6);
// swapping with $let (ensures there is no ordering dependency in vars)
-test(
- {
- $let: {
- vars: {x: 6, y: 10},
- in: {
- $let: {
- vars: {x: '$$y', y: '$$x'}, // now {x:10, y:6}
- in: {$subtract: ['$$x', '$$y']}
- }
- }
- }
- }, // not commutative!
- 4); // 10-6 not 6-10 or 6-6
+test({
+ $let: {
+ vars: {x: 6, y: 10},
+ in : {
+ $let: {
+ vars: {x: '$$y', y: '$$x'}, // now {x:10, y:6}
+ in : {$subtract: ['$$x', '$$y']}
+ }
+ }
+ }
+}, // not commutative!
+ 4); // 10-6 not 6-10 or 6-6
// unicode is allowed
-test({$let: {vars: {'日本語': 10}, in: '$$日本語'}}, 10); // Japanese for "Japanese language"
+test({$let: {vars: {'日本語': 10}, in : '$$日本語'}}, 10); // Japanese for "Japanese language"
// Can use ROOT and CURRENT directly with no subfield (SERVER-5916)
t.drop();
@@ -90,15 +85,15 @@ t.insert({_id: 'obj'});
assert.eq(t.aggregate({$project: {_id: 0, obj: '$$ROOT'}}).toArray(), [{obj: {_id: 'obj'}}]);
assert.eq(t.aggregate({$project: {_id: 0, obj: '$$CURRENT'}}).toArray(), [{obj: {_id: 'obj'}}]);
assert.eq(t.aggregate({$group: {_id: 0, objs: {$push: '$$ROOT'}}}).toArray(),
- [{_id: 0, objs: [{_id: 'obj'}]}]);
+ [{_id: 0, objs: [{_id: 'obj'}]}]);
assert.eq(t.aggregate({$group: {_id: 0, objs: {$push: '$$CURRENT'}}}).toArray(),
- [{_id: 0, objs: [{_id: 'obj'}]}]);
+ [{_id: 0, objs: [{_id: 'obj'}]}]);
// check name validity checks
-assertErrorCode(t, {$project: {a: {$let: {vars: {ROOT: 1}, in: '$$ROOT'}}}}, 16867);
-assertErrorCode(t, {$project: {a: {$let: {vars: {FOO: 1}, in: '$$FOO'}}}}, 16867);
-assertErrorCode(t, {$project: {a: {$let: {vars: {_underbar: 1}, in: '$$FOO'}}}}, 16867);
-assertErrorCode(t, {$project: {a: {$let: {vars: {'a.b': 1}, in: '$$FOO'}}}}, 16868);
-assertErrorCode(t, {$project: {a: {$let: {vars: {'a b': 1}, in: '$$FOO'}}}}, 16868);
+assertErrorCode(t, {$project: {a: {$let: {vars: {ROOT: 1}, in : '$$ROOT'}}}}, 16867);
+assertErrorCode(t, {$project: {a: {$let: {vars: {FOO: 1}, in : '$$FOO'}}}}, 16867);
+assertErrorCode(t, {$project: {a: {$let: {vars: {_underbar: 1}, in : '$$FOO'}}}}, 16867);
+assertErrorCode(t, {$project: {a: {$let: {vars: {'a.b': 1}, in : '$$FOO'}}}}, 16868);
+assertErrorCode(t, {$project: {a: {$let: {vars: {'a b': 1}, in : '$$FOO'}}}}, 16868);
assertErrorCode(t, {$project: {a: '$$_underbar'}}, 16870);
assertErrorCode(t, {$project: {a: '$$with spaces'}}, 16871);
diff --git a/jstests/aggregation/bugs/server9841.js b/jstests/aggregation/bugs/server9841.js
index 5bf9b32db93..28e6037caf1 100644
--- a/jstests/aggregation/bugs/server9841.js
+++ b/jstests/aggregation/bugs/server9841.js
@@ -16,27 +16,26 @@ function test(expression, expected) {
assert.eq(result, [{res: expected}]);
}
-test({$map: {input: "$simple", as: "var", in: '$$var'}}, [1, 2, 3, 4]);
-test({$map: {input: "$simple", as: "var", in: {$add: [10, '$$var']}}}, [11, 12, 13, 14]);
+test({$map: {input: "$simple", as: "var", in : '$$var'}}, [1, 2, 3, 4]);
+test({$map: {input: "$simple", as: "var", in : {$add: [10, '$$var']}}}, [11, 12, 13, 14]);
-test({$map: {input: "$nested", as: "var", in: '$$var.a'}}, [1, 2]);
-test({$map: {input: "$nested", as: "CURRENT", in: '$a'}}, [1, 2]);
+test({$map: {input: "$nested", as: "var", in : '$$var.a'}}, [1, 2]);
+test({$map: {input: "$nested", as: "CURRENT", in : '$a'}}, [1, 2]);
-test({$map: {input: "$mixed", as: "var", in: '$$var.a'}},
+test({$map: {input: "$mixed", as: "var", in : '$$var.a'}},
[1, null, 2, null]); // missing becomes null
-test({$map: {input: "$null", as: "var", in: '$$var'}}, null);
+test({$map: {input: "$null", as: "var", in : '$$var'}}, null);
// can't set ROOT
-assertErrorCode(t, {$project: {a: {$map: {input: "$simple", as: "ROOT", in: '$$ROOT'}}}}, 16867);
+assertErrorCode(t, {$project: {a: {$map: {input: "$simple", as: "ROOT", in : '$$ROOT'}}}}, 16867);
// error on non-array
-assertErrorCode(t, {$project: {a: {$map: {input: "$notArray", as: "var", in: '$$var'}}}}, 16883);
+assertErrorCode(t, {$project: {a: {$map: {input: "$notArray", as: "var", in : '$$var'}}}}, 16883);
// parse errors (missing or extra fields)
-assertErrorCode(t,
- {$project: {a: {$map: {x: 1, input: "$simple", as: "var", in: '$$var'}}}},
- 16879);
-assertErrorCode(t, {$project: {a: {$map: {as: "var", in: '$$var'}}}}, 16880);
-assertErrorCode(t, {$project: {a: {$map: {input: "$simple", in: '$$var'}}}}, 16881);
+assertErrorCode(
+ t, {$project: {a: {$map: {x: 1, input: "$simple", as: "var", in : '$$var'}}}}, 16879);
+assertErrorCode(t, {$project: {a: {$map: {as: "var", in : '$$var'}}}}, 16880);
+assertErrorCode(t, {$project: {a: {$map: {input: "$simple", in : '$$var'}}}}, 16881);
assertErrorCode(t, {$project: {a: {$map: {input: "$simple", as: "var"}}}}, 16882);
diff --git a/jstests/aggregation/bugs/substr.js b/jstests/aggregation/bugs/substr.js
index 9b514eb4679..8581aaf5601 100644
--- a/jstests/aggregation/bugs/substr.js
+++ b/jstests/aggregation/bugs/substr.js
@@ -108,18 +108,18 @@ assertSubstring('cde', '$z', {$add: ['$b', 1]}, {$add: [2, '$d']});
assert.eq(
'e',
t.aggregate({
- $project: {
- a: {
- $substrBytes: [
- {
- $substrBytes:
- [{$substrBytes: [{$substrBytes: ['abcdefghij', 1, 6]}, 2, 5]}, 0, 3]
- },
- 1,
- 1
- ]
- }
- }
- })
+ $project: {
+ a: {
+ $substrBytes: [
+ {
+ $substrBytes:
+ [{$substrBytes: [{$substrBytes: ['abcdefghij', 1, 6]}, 2, 5]}, 0, 3]
+ },
+ 1,
+ 1
+ ]
+ }
+ }
+ })
.toArray()[0]
.a);
diff --git a/jstests/aggregation/bugs/upperlower.js b/jstests/aggregation/bugs/upperlower.js
index 60bcba8db20..a393bf3bd72 100644
--- a/jstests/aggregation/bugs/upperlower.js
+++ b/jstests/aggregation/bugs/upperlower.js
@@ -6,8 +6,9 @@ t.drop();
t.save({});
function assertResult(expectedUpper, expectedLower, string) {
- result = t.aggregate({$project: {upper: {$toUpper: string}, lower: {$toLower: string}}})
- .toArray()[0];
+ result = t.aggregate({
+ $project: {upper: {$toUpper: string}, lower: {$toLower: string}}
+ }).toArray()[0];
assert.eq(expectedUpper, result.upper);
assert.eq(expectedLower, result.lower);
}
diff --git a/jstests/aggregation/expressions/expression_mod.js b/jstests/aggregation/expressions/expression_mod.js
index 923324797ed..63469ca8177 100644
--- a/jstests/aggregation/expressions/expression_mod.js
+++ b/jstests/aggregation/expressions/expression_mod.js
@@ -17,47 +17,44 @@ load("jstests/aggregation/extras/utils.js"); // For assertErrorCode and testExp
// The $match portion ensures they are of the correct type as the shell turns the ints back to
// doubles at the end so we can not check types with assert.
coll.save({});
- var result =
- coll.aggregate(
- {
- $project: {
- _id: 0,
- dub_dub: {$mod: [138.5, 3.0]},
- dub_int: {$mod: [138.5, NumberLong(3)]},
- dub_long: {$mod: [138.5, NumberInt(3)]},
- int_dub: {$mod: [NumberInt(8), 3.25]},
- int_dubint: {$mod: [NumberInt(8), 3.0]},
- int_int: {$mod: [NumberInt(8), NumberInt(3)]},
- int_long: {$mod: [NumberInt(8), NumberLong(3)]},
- long_dub: {$mod: [NumberLong(8), 3.25]},
- long_dubint: {$mod: [NumberLong(8), 3.0]},
- long_dublong: {$mod: [NumberLong(500000000000), 450000000000.0]},
- long_int: {$mod: [NumberLong(8), NumberInt(3)]},
- long_long: {$mod: [NumberLong(8), NumberLong(3)]},
- verylong_verylong:
- {$mod: [NumberLong(800000000000), NumberLong(300000000000)]}
- }
- },
- {
- $match: {
- // 1 is NumberDouble
- dub_dub: {$type: 1},
- dub_int: {$type: 1},
- dub_long: {$type: 1},
- int_dub: {$type: 1},
- // 16 is NumberInt
- int_dubint: {$type: 16},
- int_int: {$type: 16},
- // 18 is NumberLong
- int_long: {$type: 18},
- long_dub: {$type: 1},
- long_dubint: {$type: 18},
- long_dublong: {$type: 1},
- long_int: {$type: 18},
- long_long: {$type: 18},
- verylong_verylong: {$type: 18}
- }
- });
+ var result = coll.aggregate({
+ $project: {
+ _id: 0,
+ dub_dub: {$mod: [138.5, 3.0]},
+ dub_int: {$mod: [138.5, NumberLong(3)]},
+ dub_long: {$mod: [138.5, NumberInt(3)]},
+ int_dub: {$mod: [NumberInt(8), 3.25]},
+ int_dubint: {$mod: [NumberInt(8), 3.0]},
+ int_int: {$mod: [NumberInt(8), NumberInt(3)]},
+ int_long: {$mod: [NumberInt(8), NumberLong(3)]},
+ long_dub: {$mod: [NumberLong(8), 3.25]},
+ long_dubint: {$mod: [NumberLong(8), 3.0]},
+ long_dublong: {$mod: [NumberLong(500000000000), 450000000000.0]},
+ long_int: {$mod: [NumberLong(8), NumberInt(3)]},
+ long_long: {$mod: [NumberLong(8), NumberLong(3)]},
+ verylong_verylong: {$mod: [NumberLong(800000000000), NumberLong(300000000000)]}
+ }
+ },
+ {
+ $match: {
+ // 1 is NumberDouble
+ dub_dub: {$type: 1},
+ dub_int: {$type: 1},
+ dub_long: {$type: 1},
+ int_dub: {$type: 1},
+ // 16 is NumberInt
+ int_dubint: {$type: 16},
+ int_int: {$type: 16},
+ // 18 is NumberLong
+ int_long: {$type: 18},
+ long_dub: {$type: 1},
+ long_dubint: {$type: 18},
+ long_dublong: {$type: 1},
+ long_int: {$type: 18},
+ long_long: {$type: 18},
+ verylong_verylong: {$type: 18}
+ }
+ });
// Correct answers (it is mainly the types that are important here).
var expectedResult = [{
diff --git a/jstests/aggregation/expressions/in.js b/jstests/aggregation/expressions/in.js
index 7839c95d32e..ba09b0f8fac 100644
--- a/jstests/aggregation/expressions/in.js
+++ b/jstests/aggregation/expressions/in.js
@@ -5,13 +5,11 @@ load("jstests/aggregation/extras/utils.js"); // For assertErrorCode.
(function() {
"use strict";
- var coll = db.in;
+ var coll = db.in ;
coll.drop();
function testExpression(options) {
- var pipeline = {
- $project: {included: {$in: ["$elementField", {$literal: options.array}]}}
- };
+ var pipeline = {$project: {included: {$in: ["$elementField", {$literal: options.array}]}}};
coll.drop();
assert.writeOK(coll.insert({elementField: options.element}));
@@ -20,9 +18,7 @@ load("jstests/aggregation/extras/utils.js"); // For assertErrorCode.
assert.eq(res[0].included, options.elementIsIncluded);
if (options.queryFormShouldBeEquivalent) {
- var query = {
- elementField: {$in: options.array}
- };
+ var query = {elementField: {$in: options.array}};
res = coll.find(query).toArray();
if (options.elementIsIncluded) {
@@ -33,12 +29,8 @@ load("jstests/aggregation/extras/utils.js"); // For assertErrorCode.
}
}
- testExpression({
- element: 1,
- array: [1, 2, 3],
- elementIsIncluded: true,
- queryFormShouldBeEquivalent: true
- });
+ testExpression(
+ {element: 1, array: [1, 2, 3], elementIsIncluded: true, queryFormShouldBeEquivalent: true});
testExpression({
element: "A",
@@ -119,38 +111,24 @@ load("jstests/aggregation/extras/utils.js"); // For assertErrorCode.
coll.drop();
coll.insert({});
- var pipeline = {
- $project: {included: {$in: [[1, 2], 1]}}
- };
+ var pipeline = {$project: {included: {$in: [[1, 2], 1]}}};
assertErrorCode(coll, pipeline, 40081, "$in requires an array as a second argument");
- pipeline = {
- $project: {included: {$in: [1, null]}}
- };
+ pipeline = {$project: {included: {$in: [1, null]}}};
assertErrorCode(coll, pipeline, 40081, "$in requires an array as a second argument");
- pipeline = {
- $project: {included: {$in: [1, "$notAField"]}}
- };
+ pipeline = {$project: {included: {$in: [1, "$notAField"]}}};
assertErrorCode(coll, pipeline, 40081, "$in requires an array as a second argument");
- pipeline = {
- $project: {included: {$in: null}}
- };
+ pipeline = {$project: {included: {$in: null}}};
assertErrorCode(coll, pipeline, 16020, "$in requires two arguments");
- pipeline = {
- $project: {included: {$in: [1]}}
- };
+ pipeline = {$project: {included: {$in: [1]}}};
assertErrorCode(coll, pipeline, 16020, "$in requires two arguments");
- pipeline = {
- $project: {included: {$in: []}}
- };
+ pipeline = {$project: {included: {$in: []}}};
assertErrorCode(coll, pipeline, 16020, "$in requires two arguments");
- pipeline = {
- $project: {included: {$in: [1, 2, 3]}}
- };
+ pipeline = {$project: {included: {$in: [1, 2, 3]}}};
assertErrorCode(coll, pipeline, 16020, "$in requires two arguments");
}());
diff --git a/jstests/aggregation/expressions/indexof_array.js b/jstests/aggregation/expressions/indexof_array.js
index bfc9ef71a15..3fb445e5066 100644
--- a/jstests/aggregation/expressions/indexof_array.js
+++ b/jstests/aggregation/expressions/indexof_array.js
@@ -46,23 +46,15 @@ load("jstests/aggregation/extras/utils.js"); // For assertErrorCode and testExp
};
assertErrorCode(coll, pipeline, 40090);
- pipeline = {
- $project: {output: {$indexOfArray: [[1, 2, 3], 2, "bad"]}}
- };
+ pipeline = {$project: {output: {$indexOfArray: [[1, 2, 3], 2, "bad"]}}};
assertErrorCode(coll, pipeline, 40096);
- pipeline = {
- $project: {output: {$indexOfArray: [[1, 2, 3], 2, 0, "bad"]}}
- };
+ pipeline = {$project: {output: {$indexOfArray: [[1, 2, 3], 2, 0, "bad"]}}};
assertErrorCode(coll, pipeline, 40096);
- pipeline = {
- $project: {output: {$indexOfArray: [[1, 2, 3], 2, -1]}}
- };
+ pipeline = {$project: {output: {$indexOfArray: [[1, 2, 3], 2, -1]}}};
assertErrorCode(coll, pipeline, 40097);
- pipeline = {
- $project: {output: {$indexOfArray: [[1, 2, 3], 2, 1, -1]}}
- };
+ pipeline = {$project: {output: {$indexOfArray: [[1, 2, 3], 2, 1, -1]}}};
assertErrorCode(coll, pipeline, 40097);
}());
diff --git a/jstests/aggregation/expressions/indexof_bytes.js b/jstests/aggregation/expressions/indexof_bytes.js
index ac3cefda790..d484ad50948 100644
--- a/jstests/aggregation/expressions/indexof_bytes.js
+++ b/jstests/aggregation/expressions/indexof_bytes.js
@@ -17,9 +17,7 @@ load("jstests/aggregation/extras/utils.js"); // For assertErrorCode and testExp
var start = indexOfSpec.length > 2 ? indexOfSpec[2] : 0;
// Use $strLenBytes because JavaScript's length property is based off of UTF-16, not the
// actual number of bytes.
- var end = indexOfSpec.length > 3 ? indexOfSpec[3] : {
- $strLenBytes: input
- };
+ var end = indexOfSpec.length > 3 ? indexOfSpec[3] : {$strLenBytes: input};
var substrExpr = {
$indexOfBytes: [{$substrBytes: [input, start, {$subtract: [end, start]}]}, token]
@@ -127,23 +125,15 @@ load("jstests/aggregation/extras/utils.js"); // For assertErrorCode and testExp
};
assertErrorCode(coll, pipeline, 40092);
- pipeline = {
- $project: {output: {$indexOfBytes: ["abc", "b", "bad"]}}
- };
+ pipeline = {$project: {output: {$indexOfBytes: ["abc", "b", "bad"]}}};
assertErrorCode(coll, pipeline, 40096);
- pipeline = {
- $project: {output: {$indexOfBytes: ["abc", "b", 0, "bad"]}}
- };
+ pipeline = {$project: {output: {$indexOfBytes: ["abc", "b", 0, "bad"]}}};
assertErrorCode(coll, pipeline, 40096);
- pipeline = {
- $project: {output: {$indexOfBytes: ["abc", "b", -1]}}
- };
+ pipeline = {$project: {output: {$indexOfBytes: ["abc", "b", -1]}}};
assertErrorCode(coll, pipeline, 40097);
- pipeline = {
- $project: {output: {$indexOfBytes: ["abc", "b", 1, -1]}}
- };
+ pipeline = {$project: {output: {$indexOfBytes: ["abc", "b", 1, -1]}}};
assertErrorCode(coll, pipeline, 40097);
}());
diff --git a/jstests/aggregation/expressions/indexof_codepoints.js b/jstests/aggregation/expressions/indexof_codepoints.js
index 20b9534b050..506b1a13cfa 100644
--- a/jstests/aggregation/expressions/indexof_codepoints.js
+++ b/jstests/aggregation/expressions/indexof_codepoints.js
@@ -15,9 +15,7 @@ load("jstests/aggregation/extras/utils.js"); // For assertErrorCode and testExp
var input = indexOfSpec[0];
var token = indexOfSpec[1];
var start = indexOfSpec.length > 2 ? indexOfSpec[2] : 0;
- var end = indexOfSpec.length > 3 ? indexOfSpec[3] : {
- $strLenCP: input
- };
+ var end = indexOfSpec.length > 3 ? indexOfSpec[3] : {$strLenCP: input};
var substrExpr = {
$indexOfCP: [{$substrCP: [input, start, {$subtract: [end, start]}]}, token]
@@ -107,23 +105,15 @@ load("jstests/aggregation/extras/utils.js"); // For assertErrorCode and testExp
};
assertErrorCode(coll, pipeline, 40094);
- pipeline = {
- $project: {output: {$indexOfCP: ["abc", "b", "bad"]}}
- };
+ pipeline = {$project: {output: {$indexOfCP: ["abc", "b", "bad"]}}};
assertErrorCode(coll, pipeline, 40096);
- pipeline = {
- $project: {output: {$indexOfCP: ["abc", "b", 0, "bad"]}}
- };
+ pipeline = {$project: {output: {$indexOfCP: ["abc", "b", 0, "bad"]}}};
assertErrorCode(coll, pipeline, 40096);
- pipeline = {
- $project: {output: {$indexOfCP: ["abc", "b", -1]}}
- };
+ pipeline = {$project: {output: {$indexOfCP: ["abc", "b", -1]}}};
assertErrorCode(coll, pipeline, 40097);
- pipeline = {
- $project: {output: {$indexOfCP: ["abc", "b", 1, -1]}}
- };
+ pipeline = {$project: {output: {$indexOfCP: ["abc", "b", 1, -1]}}};
assertErrorCode(coll, pipeline, 40097);
}());
diff --git a/jstests/aggregation/expressions/reduce.js b/jstests/aggregation/expressions/reduce.js
index 73bb0cfa16f..54a66fc8b56 100644
--- a/jstests/aggregation/expressions/reduce.js
+++ b/jstests/aggregation/expressions/reduce.js
@@ -11,15 +11,15 @@ load("jstests/aggregation/extras/utils.js"); // For assertErrorCode and testExp
coll,
{
$reduce:
- {input: [1, 2, 3], initialValue: {$literal: 0}, in: {$sum: ["$$this", "$$value"]}}
+ {input: [1, 2, 3], initialValue: {$literal: 0}, in : {$sum: ["$$this", "$$value"]}}
},
6);
- testExpression(coll, {$reduce: {input: [], initialValue: {$literal: 0}, in: 10}}, 0);
+ testExpression(coll, {$reduce: {input: [], initialValue: {$literal: 0}, in : 10}}, 0);
testExpression(
coll,
{
$reduce:
- {input: [1, 2, 3], initialValue: [], in: {$concatArrays: ["$$value", ["$$this"]]}}
+ {input: [1, 2, 3], initialValue: [], in : {$concatArrays: ["$$value", ["$$this"]]}}
},
[1, 2, 3]);
testExpression(coll,
@@ -27,7 +27,7 @@ load("jstests/aggregation/extras/utils.js"); // For assertErrorCode and testExp
$reduce: {
input: [1, 2],
initialValue: [],
- in: {$concatArrays: ["$$value", ["$$value.notAField"]]}
+ in : {$concatArrays: ["$$value", ["$$value.notAField"]]}
}
},
[[], []]);
@@ -38,14 +38,14 @@ load("jstests/aggregation/extras/utils.js"); // For assertErrorCode and testExp
$reduce: {
input: [[1, 2, 3], [4, 5]],
initialValue: 1,
- in: {
+ in : {
$multiply: [
"$$value",
{
$reduce: {
input: "$$this",
initialValue: 0,
- in: {$sum: ["$$value", "$$this"]}
+ in : {$sum: ["$$value", "$$this"]}
}
}
]
@@ -56,43 +56,43 @@ load("jstests/aggregation/extras/utils.js"); // For assertErrorCode and testExp
// A nested $reduce using a $let to allow the inner $reduce to access the variables of the
// outer.
- testExpression(
- coll,
- {
- $reduce: {
- input: [[0, 1], [2, 3]],
- initialValue: {allElements: [], sumOfInner: {$literal: 0}},
- in: {
- $let: {
- vars: {outerValue: "$$value", innerArray: "$$this"},
- in: {
- $reduce: {
- input: "$$innerArray",
- initialValue: "$$outerValue",
- in: {
- allElements:
- {$concatArrays: ["$$value.allElements", ["$$this"]]},
- sumOfInner: {$sum: ["$$value.sumOfInner", "$$this"]}
- }
- }
- }
- }
- }
- }
- },
- {allElements: [0, 1, 2, 3], sumOfInner: 6});
+ testExpression(coll,
+ {
+ $reduce: {
+ input: [[0, 1], [2, 3]],
+ initialValue: {allElements: [], sumOfInner: {$literal: 0}},
+ in : {
+ $let: {
+ vars: {outerValue: "$$value", innerArray: "$$this"},
+ in : {
+ $reduce: {
+ input: "$$innerArray",
+ initialValue: "$$outerValue",
+ in : {
+ allElements: {
+ $concatArrays:
+ ["$$value.allElements", ["$$this"]]
+ },
+ sumOfInner:
+ {$sum: ["$$value.sumOfInner", "$$this"]}
+ }
+ }
+ }
+ }
+ }
+ }
+ },
+ {allElements: [0, 1, 2, 3], sumOfInner: 6});
// Nullish input produces null as an output.
- testExpression(coll, {$reduce: {input: null, initialValue: {$literal: 0}, in: 5}}, null);
+ testExpression(coll, {$reduce: {input: null, initialValue: {$literal: 0}, in : 5}}, null);
testExpression(
- coll, {$reduce: {input: "$nonexistent", initialValue: {$literal: 0}, in: 5}}, null);
+ coll, {$reduce: {input: "$nonexistent", initialValue: {$literal: 0}, in : 5}}, null);
// Error cases for $reduce.
// $reduce requires an object.
- var pipeline = {
- $project: {reduced: {$reduce: 0}}
- };
+ var pipeline = {$project: {reduced: {$reduce: 0}}};
assertErrorCode(coll, pipeline, 40075);
// Unknown field specified.
@@ -102,7 +102,7 @@ load("jstests/aggregation/extras/utils.js"); // For assertErrorCode and testExp
$reduce: {
input: {$literal: 0},
initialValue: {$literal: 0},
- in: {$literal: 0},
+ in : {$literal: 0},
notAField: {$literal: 0}
}
}
@@ -111,15 +111,11 @@ load("jstests/aggregation/extras/utils.js"); // For assertErrorCode and testExp
assertErrorCode(coll, pipeline, 40076);
// $reduce requires input to be specified.
- pipeline = {
- $project: {reduced: {$reduce: {initialValue: {$literal: 0}, in: {$literal: 0}}}}
- };
+ pipeline = {$project: {reduced: {$reduce: {initialValue: {$literal: 0}, in : {$literal: 0}}}}};
assertErrorCode(coll, pipeline, 40077);
// $reduce requires initialValue to be specified.
- pipeline = {
- $project: {reduced: {$reduce: {input: {$literal: 0}, in: {$literal: 0}}}}
- };
+ pipeline = {$project: {reduced: {$reduce: {input: {$literal: 0}, in : {$literal: 0}}}}};
assertErrorCode(coll, pipeline, 40078);
// $reduce requires in to be specified.
@@ -129,14 +125,10 @@ load("jstests/aggregation/extras/utils.js"); // For assertErrorCode and testExp
assertErrorCode(coll, pipeline, 40079);
// $$value is undefined in the non-'in' arguments of $reduce.
- pipeline = {
- $project: {reduced: {$reduce: {input: "$$value", initialValue: [], in: []}}}
- };
+ pipeline = {$project: {reduced: {$reduce: {input: "$$value", initialValue: [], in : []}}}};
assertErrorCode(coll, pipeline, 17276);
// $$this is undefined in the non-'in' arguments of $reduce.
- pipeline = {
- $project: {reduced: {$reduce: {input: "$$this", initialValue: [], in: []}}}
- };
+ pipeline = {$project: {reduced: {$reduce: {input: "$$this", initialValue: [], in : []}}}};
assertErrorCode(coll, pipeline, 17276);
}());
diff --git a/jstests/aggregation/expressions/split.js b/jstests/aggregation/expressions/split.js
index bfed38314b4..7d3402bde4e 100644
--- a/jstests/aggregation/expressions/split.js
+++ b/jstests/aggregation/expressions/split.js
@@ -38,35 +38,23 @@ load("jstests/aggregation/extras/utils.js"); // For assertErrorCode and testExp
testExpression(coll, {$split: ["a", "$a"]}, null);
// Ensure that $split errors when given more or less than two arguments.
- var pipeline = {
- $project: {split: {$split: []}}
- };
+ var pipeline = {$project: {split: {$split: []}}};
assertErrorCode(coll, pipeline, 16020);
- pipeline = {
- $project: {split: {$split: ["a"]}}
- };
+ pipeline = {$project: {split: {$split: ["a"]}}};
assertErrorCode(coll, pipeline, 16020);
- pipeline = {
- $project: {split: {$split: ["a", "b", "c"]}}
- };
+ pipeline = {$project: {split: {$split: ["a", "b", "c"]}}};
assertErrorCode(coll, pipeline, 16020);
// Ensure that $split errors when given non-string input.
- pipeline = {
- $project: {split: {$split: [1, "abc"]}}
- };
+ pipeline = {$project: {split: {$split: [1, "abc"]}}};
assertErrorCode(coll, pipeline, 40085);
- pipeline = {
- $project: {split: {$split: ["abc", 1]}}
- };
+ pipeline = {$project: {split: {$split: ["abc", 1]}}};
assertErrorCode(coll, pipeline, 40086);
// Ensure that $split errors when given an empty separator.
- pipeline = {
- $project: {split: {$split: ["abc", ""]}}
- };
+ pipeline = {$project: {split: {$split: ["abc", ""]}}};
assertErrorCode(coll, pipeline, 40087);
}());
diff --git a/jstests/aggregation/expressions/switch.js b/jstests/aggregation/expressions/switch.js
index 9a6dbbb529d..64cd9e1db2f 100644
--- a/jstests/aggregation/expressions/switch.js
+++ b/jstests/aggregation/expressions/switch.js
@@ -99,8 +99,7 @@
pipeline = {
"$project": {
"_id": 0,
- "output":
- {"$switch": {"branches": [{"case": true, "then": null}], "default": false}}
+ "output": {"$switch": {"branches": [{"case": true, "then": null}], "default": false}}
}
};
res = coll.aggregate(pipeline).toArray();
@@ -125,8 +124,7 @@
pipeline = {
"$project": {
"_id": 0,
- "output":
- {"$switch": {"branches": [{"case": null, "then": false}], "default": null}}
+ "output": {"$switch": {"branches": [{"case": null, "then": false}], "default": null}}
}
};
res = coll.aggregate(pipeline).toArray();
diff --git a/jstests/aggregation/expressions/switch_errors.js b/jstests/aggregation/expressions/switch_errors.js
index cf6dc0f4f93..0d9023fb250 100644
--- a/jstests/aggregation/expressions/switch_errors.js
+++ b/jstests/aggregation/expressions/switch_errors.js
@@ -8,24 +8,16 @@ load("jstests/aggregation/extras/utils.js"); // For assertErrorCode.
var coll = db.switch;
coll.drop();
- var pipeline = {
- "$project": {"output": {"$switch": "not an object"}}
- };
+ var pipeline = {"$project": {"output": {"$switch": "not an object"}}};
assertErrorCode(coll, pipeline, 40060, "$switch requires an object as an argument.");
- pipeline = {
- "$project": {"output": {"$switch": {"branches": "not an array"}}}
- };
+ pipeline = {"$project": {"output": {"$switch": {"branches": "not an array"}}}};
assertErrorCode(coll, pipeline, 40061, "$switch requires 'branches' to be an array.");
- pipeline = {
- "$project": {"output": {"$switch": {"branches": ["not an object"]}}}
- };
+ pipeline = {"$project": {"output": {"$switch": {"branches": ["not an object"]}}}};
assertErrorCode(coll, pipeline, 40062, "$switch requires each branch to be an object.");
- pipeline = {
- "$project": {"output": {"$switch": {"branches": [{}]}}}
- };
+ pipeline = {"$project": {"output": {"$switch": {"branches": [{}]}}}};
assertErrorCode(coll, pipeline, 40064, "$switch requires each branch have a 'case'.");
pipeline = {
@@ -47,19 +39,13 @@ load("jstests/aggregation/extras/utils.js"); // For assertErrorCode.
};
assertErrorCode(coll, pipeline, 40063, "$switch found a branch with an unknown argument");
- pipeline = {
- "$project": {"output": {"$switch": {"notAnArgument": 1}}}
- };
+ pipeline = {"$project": {"output": {"$switch": {"notAnArgument": 1}}}};
assertErrorCode(coll, pipeline, 40067, "$switch found an unknown argument");
- pipeline = {
- "$project": {"output": {"$switch": {"branches": []}}}
- };
+ pipeline = {"$project": {"output": {"$switch": {"branches": []}}}};
assertErrorCode(coll, pipeline, 40068, "$switch requires at least one branch");
- pipeline = {
- "$project": {"output": {"$switch": {}}}
- };
+ pipeline = {"$project": {"output": {"$switch": {}}}};
assertErrorCode(coll, pipeline, 40068, "$switch requires at least one branch");
coll.insert({x: 1});
diff --git a/jstests/aggregation/extras/mrabench.js b/jstests/aggregation/extras/mrabench.js
index fe731ecd28b..78be64a2064 100644
--- a/jstests/aggregation/extras/mrabench.js
+++ b/jstests/aggregation/extras/mrabench.js
@@ -11,10 +11,7 @@ function rollupMap() {
}
function rollupReduce(key, values) {
- var res = {
- total: 0,
- unique: 0
- };
+ var res = {total: 0, unique: 0};
for (var i = 0; i < values.length; i++) {
res.total += values[i].total;
res.unique += values[i].unique;
@@ -41,15 +38,13 @@ function rollupWeeklyMR() {
function rollupMonthlyA() {
resMonthlyA = db.runCommand({
aggregate: "gen.monthly.ip",
- pipeline:
- [{$group: {_id: {month: "_id.t"}, total: {$sum: "$value"}, unique: {$sum: 1}}}]
+ pipeline: [{$group: {_id: {month: "_id.t"}, total: {$sum: "$value"}, unique: {$sum: 1}}}]
});
}
function rollupWeeklyA() {
resWeeklyA = db.runCommand({
aggregate: "gen.weekly.ip",
- pipeline:
- [{$group: {_id: {month: "_id.t"}, total: {$sum: "$value"}, unique: {$sum: 1}}}]
+ pipeline: [{$group: {_id: {month: "_id.t"}, total: {$sum: "$value"}, unique: {$sum: 1}}}]
});
}
diff --git a/jstests/aggregation/extras/testutils.js b/jstests/aggregation/extras/testutils.js
index bb753921906..bd05ea835f0 100644
--- a/jstests/aggregation/extras/testutils.js
+++ b/jstests/aggregation/extras/testutils.js
@@ -39,7 +39,13 @@ assert(!resultsEq(t1result, t1resultf2, verbose), 't2a failed');
assert(!resultsEq(t1resultf2, t1result, verbose), 't2b failed');
var t1resultf3 = [
- {"_id": ObjectId("4dc07fedd8420ab8d0d4066d"), "pageViews": 5, "tags": ["fun", ]},
+ {
+ "_id": ObjectId("4dc07fedd8420ab8d0d4066d"),
+ "pageViews": 5,
+ "tags": [
+ "fun",
+ ]
+ },
{"_id": ObjectId("4dc07fedd8420ab8d0d4066e"), "pageViews": 7, "tags": ["fun", "nasty"]},
{"_id": ObjectId("4dc07fedd8420ab8d0d4066f"), "pageViews": 6, "tags": ["filthy"]}
];
diff --git a/jstests/aggregation/extras/utils.js b/jstests/aggregation/extras/utils.js
index 33cfe9b2b2b..7fca7aa0ca3 100644
--- a/jstests/aggregation/extras/utils.js
+++ b/jstests/aggregation/extras/utils.js
@@ -259,13 +259,9 @@ function assertErrorCode(coll, pipe, code, errmsg) {
assert.eq(res.code, code);
// Test with cursors
- var cmd = {
- pipeline: pipe
- };
+ var cmd = {pipeline: pipe};
// cmd.cursor = {};
- cmd.cursor = {
- batchSize: 0
- };
+ cmd.cursor = {batchSize: 0};
var cursorRes = coll.runCommand("aggregate", cmd);
if (cursorRes.ok) {
diff --git a/jstests/aggregation/mongos_slaveok.js b/jstests/aggregation/mongos_slaveok.js
index 91a0533d59e..9ccf383335e 100644
--- a/jstests/aggregation/mongos_slaveok.js
+++ b/jstests/aggregation/mongos_slaveok.js
@@ -26,10 +26,7 @@
var res = testDB.runCommand({aggregate: 'user', pipeline: [{$project: {x: 1}}]});
assert(res.ok, 'aggregate command failed: ' + tojson(res));
- var profileQuery = {
- op: 'command',
- ns: 'test.user', 'command.aggregate': 'user'
- };
+ var profileQuery = {op: 'command', ns: 'test.user', 'command.aggregate': 'user'};
var profileDoc = secNode.getDB('test').system.profile.findOne(profileQuery);
assert(profileDoc != null);
diff --git a/jstests/aggregation/sources/graphLookup/airports.js b/jstests/aggregation/sources/graphLookup/airports.js
index 7cf0142c631..71a38e268b8 100644
--- a/jstests/aggregation/sources/graphLookup/airports.js
+++ b/jstests/aggregation/sources/graphLookup/airports.js
@@ -30,45 +30,39 @@
local.insert({});
// Perform a simple $graphLookup and ensure it retrieves every result.
- var res = local.aggregate({
- $graphLookup: {
- from: "foreign",
- startWith: "PWM",
- connectFromField: "connects",
- connectToField: "_id",
- as: "connections"
- }
- }).toArray()[0];
-
- // "foreign" represents a connected graph.
- assert.eq(res.connections.length, airports.length);
-
- // Perform a $graphLookup and ensure it correctly computes the shortest path to a node when more
- // than one path exists.
- res = local.aggregate(
- {
+ var res = local
+ .aggregate({
$graphLookup: {
from: "foreign",
- startWith: "BOS",
+ startWith: "PWM",
connectFromField: "connects",
connectToField: "_id",
- depthField: "hops",
as: "connections"
}
- },
- {$unwind: "$connections"},
- {$project: {_id: "$connections._id", hops: "$connections.hops"}}).toArray();
+ })
+ .toArray()[0];
+
+ // "foreign" represents a connected graph.
+ assert.eq(res.connections.length, airports.length);
+
+ // Perform a $graphLookup and ensure it correctly computes the shortest path to a node when more
+ // than one path exists.
+ res = local
+ .aggregate({
+ $graphLookup: {
+ from: "foreign",
+ startWith: "BOS",
+ connectFromField: "connects",
+ connectToField: "_id",
+ depthField: "hops",
+ as: "connections"
+ }
+ },
+ {$unwind: "$connections"},
+ {$project: {_id: "$connections._id", hops: "$connections.hops"}})
+ .toArray();
- var expectedDistances = {
- BOS: 0,
- PWM: 1,
- JFK: 1,
- LGA: 1,
- ORD: 2,
- SFO: 2,
- MIA: 3,
- ATL: 4
- };
+ var expectedDistances = {BOS: 0, PWM: 1, JFK: 1, LGA: 1, ORD: 2, SFO: 2, MIA: 3, ATL: 4};
assert.eq(res.length, airports.length);
res.forEach(function(c) {
@@ -78,15 +72,17 @@
// Disconnect the graph, and ensure we don't find the other side.
foreign.remove({_id: "JFK"});
- res = db.local.aggregate({
- $graphLookup: {
- from: "foreign",
- startWith: "ATL",
- connectFromField: "connects",
- connectToField: "_id",
- as: "connections"
- }
- }).toArray()[0];
+ res = db.local
+ .aggregate({
+ $graphLookup: {
+ from: "foreign",
+ startWith: "ATL",
+ connectFromField: "connects",
+ connectToField: "_id",
+ as: "connections"
+ }
+ })
+ .toArray()[0];
// ATL should now connect to itself, MIA, and SFO.
assert.eq(res.connections.length, 3);
diff --git a/jstests/aggregation/sources/graphLookup/basic.js b/jstests/aggregation/sources/graphLookup/basic.js
index 8ee26a64f9f..15c8ef85e22 100644
--- a/jstests/aggregation/sources/graphLookup/basic.js
+++ b/jstests/aggregation/sources/graphLookup/basic.js
@@ -19,59 +19,67 @@
assert.writeOK(local.insert({starting: 50}));
// Perform a simple $graphLookup and ensure it retrieves every result.
- var res = local.aggregate({
- $graphLookup: {
- from: "foreign",
- startWith: "$starting",
- connectFromField: "neighbors",
- connectToField: "_id",
- as: "integers"
- }
- }).toArray()[0];
+ var res = local
+ .aggregate({
+ $graphLookup: {
+ from: "foreign",
+ startWith: "$starting",
+ connectFromField: "neighbors",
+ connectToField: "_id",
+ as: "integers"
+ }
+ })
+ .toArray()[0];
assert.eq(res.integers.length, 100);
// Perform a $graphLookup and ensure it respects "maxDepth".
- res = local.aggregate({
- $graphLookup: {
- from: "foreign",
- startWith: "$starting",
- connectFromField: "neighbors",
- connectToField: "_id",
- maxDepth: 5,
- as: "integers"
- }
- }).toArray()[0];
+ res = local
+ .aggregate({
+ $graphLookup: {
+ from: "foreign",
+ startWith: "$starting",
+ connectFromField: "neighbors",
+ connectToField: "_id",
+ maxDepth: 5,
+ as: "integers"
+ }
+ })
+ .toArray()[0];
// At depth zero, we retrieve one integer, and two for every depth thereafter.
assert.eq(res.integers.length, 11);
// Perform a $graphLookup and ensure it properly evaluates "startWith".
- res = local.aggregate({
- $graphLookup: {
- from: "foreign",
- startWith: {$add: ["$starting", 3]},
- connectFromField: "neighbors",
- connectToField: "_id",
- maxDepth: 0,
- as: "integers"
- }
- }).toArray()[0];
+ res = local
+ .aggregate({
+ $graphLookup: {
+ from: "foreign",
+ startWith: {$add: ["$starting", 3]},
+ connectFromField: "neighbors",
+ connectToField: "_id",
+ maxDepth: 0,
+ as: "integers"
+ }
+ })
+ .toArray()[0];
assert.eq(res.integers.length, 1);
assert.eq(res.integers[0]._id, 53);
// Perform a $graphLookup and ensure it properly expands "startWith".
- res = local.aggregate({
- $graphLookup: {
- from: "foreign",
- startWith: {$literal: [1, 2, 3]},
- connectFromField: "neighbors",
- connectToField: "_id",
- maxDepth: 0,
- as: "integers"
- }
- }).toArray()[0];
+ res = local
+ .aggregate({
+ $graphLookup: {
+ from: "foreign",
+ startWith: {$literal: [1, 2, 3]},
+ connectFromField: "neighbors",
+ connectToField: "_id",
+ maxDepth: 0,
+ as: "integers"
+ }
+ })
+ .toArray()[0];
assert.eq(res.integers.length, 3);
@@ -83,15 +91,17 @@
assert.writeOK(foreign.insert({_id: 51}));
assert.writeOK(foreign.insert({_id: null, neighbors: [50, 52]}));
- res = local.aggregate({
- $graphLookup: {
- from: "foreign",
- startWith: "$starting",
- connectFromField: "neighbors",
- connectToField: "_id",
- as: "integers"
- }
- }).toArray()[0];
+ res = local
+ .aggregate({
+ $graphLookup: {
+ from: "foreign",
+ startWith: "$starting",
+ connectFromField: "neighbors",
+ connectToField: "_id",
+ as: "integers"
+ }
+ })
+ .toArray()[0];
// Our result should be missing the values with _id from 52 to 99.
assert.eq(res.integers.length, 52);
@@ -103,29 +113,33 @@
assert.writeOK(foreign.update({_id: 99}, {$set: {neighbors: [98, 0]}}));
assert.writeOK(foreign.update({_id: 0}, {$set: {neighbors: [99, 1]}}));
- res = local.aggregate({
- $graphLookup: {
- from: "foreign",
- startWith: "$starting",
- connectFromField: "neighbors",
- connectToField: "_id",
- as: "integers"
- }
- }).toArray()[0];
+ res = local
+ .aggregate({
+ $graphLookup: {
+ from: "foreign",
+ startWith: "$starting",
+ connectFromField: "neighbors",
+ connectToField: "_id",
+ as: "integers"
+ }
+ })
+ .toArray()[0];
assert.eq(res.integers.length, 100);
// Perform a $graphLookup and ensure that "depthField" is properly populated.
- res = local.aggregate({
- $graphLookup: {
- from: "foreign",
- startWith: "$starting",
- connectFromField: "neighbors",
- connectToField: "_id",
- depthField: "distance",
- as: "integers"
- }
- }).toArray()[0];
+ res = local
+ .aggregate({
+ $graphLookup: {
+ from: "foreign",
+ startWith: "$starting",
+ connectFromField: "neighbors",
+ connectToField: "_id",
+ depthField: "distance",
+ as: "integers"
+ }
+ })
+ .toArray()[0];
assert.eq(res.integers.length, 100);
diff --git a/jstests/aggregation/sources/graphLookup/error.js b/jstests/aggregation/sources/graphLookup/error.js
index 70e9d2a8079..721bce5eb3e 100644
--- a/jstests/aggregation/sources/graphLookup/error.js
+++ b/jstests/aggregation/sources/graphLookup/error.js
@@ -165,8 +165,7 @@ load("jstests/aggregation/extras/utils.js"); // For "assertErrorCode".
assertErrorCode(local, pipeline, 40105, "connectToField was not specified");
pipeline = {
- $graphLookup:
- {from: "foreign", startWith: {$const: 0}, connectToField: "a", as: "output"}
+ $graphLookup: {from: "foreign", startWith: {$const: 0}, connectToField: "a", as: "output"}
};
assertErrorCode(local, pipeline, 40105, "connectFromField was not specified");
@@ -211,9 +210,7 @@ load("jstests/aggregation/extras/utils.js"); // For "assertErrorCode".
var initial = [];
for (var i = 0; i < 8; i++) {
- var obj = {
- _id: i
- };
+ var obj = {_id: i};
obj['longString'] = new Array(14 * 1024 * 1024).join('x');
initial.push(i);
@@ -238,10 +235,7 @@ load("jstests/aggregation/extras/utils.js"); // For "assertErrorCode".
var bulk = foreign.initializeUnorderedBulkOp();
for (var i = 0; i < 14; i++) {
- var obj = {
- from: 0,
- to: 1
- };
+ var obj = {from: 0, to: 1};
obj['s'] = new Array(7 * 1024 * 1024).join(' ');
bulk.insert(obj);
}
@@ -264,26 +258,24 @@ load("jstests/aggregation/extras/utils.js"); // For "assertErrorCode".
var bulk = foreign.initializeUnorderedBulkOp();
for (var i = 0; i < 13; i++) {
- var obj = {
- from: 0,
- to: 1
- };
+ var obj = {from: 0, to: 1};
obj['s'] = new Array(7 * 1024 * 1024).join(' ');
bulk.insert(obj);
}
assert.writeOK(bulk.execute());
- var res = local.aggregate(
- {
- $graphLookup: {
- from: "foreign",
- startWith: {$literal: 0},
- connectToField: "from",
- connectFromField: "to",
- as: "out"
- }
- },
- {$unwind: {path: "$out"}}).toArray();
+ var res = local
+ .aggregate({
+ $graphLookup: {
+ from: "foreign",
+ startWith: {$literal: 0},
+ connectToField: "from",
+ connectFromField: "to",
+ as: "out"
+ }
+ },
+ {$unwind: {path: "$out"}})
+ .toArray();
assert.eq(res.length, 13);
}());
diff --git a/jstests/aggregation/sources/graphLookup/nested_objects.js b/jstests/aggregation/sources/graphLookup/nested_objects.js
index e95d99f293f..b2e3f5ac59a 100644
--- a/jstests/aggregation/sources/graphLookup/nested_objects.js
+++ b/jstests/aggregation/sources/graphLookup/nested_objects.js
@@ -19,15 +19,17 @@
assert.writeOK(local.insert({starting: 0}));
- var res = local.aggregate({
- $graphLookup: {
- from: "foreign",
- startWith: "$starting",
- connectFromField: "neighbors.id",
- connectToField: "_id",
- as: "integers"
- }
- }).toArray()[0];
+ var res = local
+ .aggregate({
+ $graphLookup: {
+ from: "foreign",
+ startWith: "$starting",
+ connectFromField: "neighbors.id",
+ connectToField: "_id",
+ as: "integers"
+ }
+ })
+ .toArray()[0];
assert.eq(res.integers.length, 100);
foreign.drop();
@@ -39,15 +41,17 @@
}
assert.writeOK(bulk.execute());
- var res = local.aggregate({
- $graphLookup: {
- from: "foreign",
- startWith: "$starting",
- connectFromField: "value",
- connectToField: "previous.neighbor",
- as: "integers"
- }
- }).toArray()[0];
+ var res = local
+ .aggregate({
+ $graphLookup: {
+ from: "foreign",
+ startWith: "$starting",
+ connectFromField: "value",
+ connectToField: "previous.neighbor",
+ as: "integers"
+ }
+ })
+ .toArray()[0];
assert.eq(res.integers.length, 100);
foreign.drop();
@@ -62,14 +66,16 @@
}
assert.writeOK(bulk.execute());
- var res = local.aggregate({
- $graphLookup: {
- from: "foreign",
- startWith: "$starting",
- connectFromField: "values.neighbor",
- connectToField: "previous.neighbor",
- as: "integers"
- }
- }).toArray()[0];
+ var res = local
+ .aggregate({
+ $graphLookup: {
+ from: "foreign",
+ startWith: "$starting",
+ connectFromField: "values.neighbor",
+ connectToField: "previous.neighbor",
+ as: "integers"
+ }
+ })
+ .toArray()[0];
assert.eq(res.integers.length, 100);
}());
diff --git a/jstests/aggregation/sources/graphLookup/sharded.js b/jstests/aggregation/sources/graphLookup/sharded.js
index 26fbbc2e9f0..d54e2be01c8 100644
--- a/jstests/aggregation/sources/graphLookup/sharded.js
+++ b/jstests/aggregation/sources/graphLookup/sharded.js
@@ -24,7 +24,8 @@ load("jstests/aggregation/extras/utils.js"); // For assertErrorCode.
assert.writeOK(local.insert({}));
var res = st.s.getDB("graphLookup")
- .local.aggregate({
+ .local
+ .aggregate({
$graphLookup: {
from: "foreign",
startWith: {$literal: 0},
diff --git a/jstests/aggregation/sources/graphLookup/socialite.js b/jstests/aggregation/sources/graphLookup/socialite.js
index 21027f21b0b..6efe2672540 100644
--- a/jstests/aggregation/sources/graphLookup/socialite.js
+++ b/jstests/aggregation/sources/graphLookup/socialite.js
@@ -30,18 +30,20 @@
// Find the social network of "Darren", that is, people Darren follows, and people who are
// followed by someone Darren follows, etc.
- var res = users.aggregate({$match: {fullname: "Darren"}},
- {
- $graphLookup: {
- from: "followers",
- startWith: "$_id",
- connectFromField: "_t",
- connectToField: "_f",
- as: "network"
- }
- },
- {$unwind: "$network"},
- {$project: {_id: "$network._t"}}).toArray();
+ var res = users
+ .aggregate({$match: {fullname: "Darren"}},
+ {
+ $graphLookup: {
+ from: "followers",
+ startWith: "$_id",
+ connectFromField: "_t",
+ connectToField: "_f",
+ as: "network"
+ }
+ },
+ {$unwind: "$network"},
+ {$project: {_id: "$network._t"}})
+ .toArray();
// "djw" is followed, directly or indirectly, by "jsr" and "bmw".
assert.eq(res.length, 2);
diff --git a/jstests/aggregation/testSlave.js b/jstests/aggregation/testSlave.js
index 21a798a1ad2..0a03d68a49b 100644
--- a/jstests/aggregation/testSlave.js
+++ b/jstests/aggregation/testSlave.js
@@ -7,9 +7,7 @@ replTest.awaitReplication();
var primary = replTest.getPrimary().getDB('test');
var secondary = replTest.getSecondary().getDB('test');
-var options = {
- writeConcern: {w: 2}
-};
+var options = {writeConcern: {w: 2}};
primary.agg.insert({}, options);
primary.agg.insert({}, options);
primary.agg.insert({}, options);
diff --git a/jstests/aggregation/testall.js b/jstests/aggregation/testall.js
index 5771cbefaef..c58d3e1e023 100644
--- a/jstests/aggregation/testall.js
+++ b/jstests/aggregation/testall.js
@@ -370,7 +370,10 @@ db.p11.save({
var p11 = db.runCommand({
aggregate: "p11",
- pipeline: [{$unwind: "$items.authors"}, {$project: {name: 1, author: "$items.authors"}}, ]
+ pipeline: [
+ {$unwind: "$items.authors"},
+ {$project: {name: 1, author: "$items.authors"}},
+ ]
});
p11result = [
@@ -418,8 +421,14 @@ assert.docEq(p13.result, p13result, 'p13 failed');
var p14 = db.runCommand({
aggregate: "article",
pipeline: [{
- $project:
- {theRemainder: {$mod: [{$ifNull: ["$other.foo", "$other.bar"]}, "$pageViews", ]}}
+ $project: {
+ theRemainder: {
+ $mod: [
+ {$ifNull: ["$other.foo", "$other.bar"]},
+ "$pageViews",
+ ]
+ }
+ }
}]
});
@@ -788,9 +797,21 @@ g5.result.forEach(function(obj) {
var g5result = [
{"_id": {"tags": "filthy"}, "authors": ["jane"]},
- {"_id": {"tags": "fun"}, "authors": ["bob", "dave", ]},
+ {
+ "_id": {"tags": "fun"},
+ "authors": [
+ "bob",
+ "dave",
+ ]
+ },
{"_id": {"tags": "good"}, "authors": ["bob"]},
- {"_id": {"tags": "nasty"}, "authors": ["dave", "jane", ]}
+ {
+ "_id": {"tags": "nasty"},
+ "authors": [
+ "dave",
+ "jane",
+ ]
+ }
];
assert.docEq(g5.result, g5result, 'g5 failed');
diff --git a/jstests/aggregation/testshard1.js b/jstests/aggregation/testshard1.js
index 0d773351f1d..516325cbe5c 100644
--- a/jstests/aggregation/testshard1.js
+++ b/jstests/aggregation/testshard1.js
@@ -46,26 +46,9 @@ being added as arrays within arrays.
var count = 0;
var strings = [
- "one",
- "two",
- "three",
- "four",
- "five",
- "six",
- "seven",
- "eight",
- "nine",
- "ten",
- "eleven",
- "twelve",
- "thirteen",
- "fourteen",
- "fifteen",
- "sixteen",
- "seventeen",
- "eighteen",
- "nineteen",
- "twenty"
+ "one", "two", "three", "four", "five", "six", "seven",
+ "eight", "nine", "ten", "eleven", "twelve", "thirteen", "fourteen",
+ "fifteen", "sixteen", "seventeen", "eighteen", "nineteen", "twenty"
];
jsTestLog("Bulk inserting data");
@@ -94,13 +77,11 @@ for (var i = 0; i < shards.length; i++) {
}
jsTestLog('a project and group in shards, result combined in mongos');
-var a1 = aggregateNoOrder(
- db.ts1,
- [
- {$project: {cMod10: {$mod: ["$counter", 10]}, number: 1, counter: 1}},
- {$group: {_id: "$cMod10", numberSet: {$addToSet: "$number"}, avgCounter: {$avg: "$cMod10"}}},
- {$sort: {_id: 1}}
- ]);
+var a1 = aggregateNoOrder(db.ts1, [
+ {$project: {cMod10: {$mod: ["$counter", 10]}, number: 1, counter: 1}},
+ {$group: {_id: "$cMod10", numberSet: {$addToSet: "$number"}, avgCounter: {$avg: "$cMod10"}}},
+ {$sort: {_id: 1}}
+]);
for (i = 0; i < 10; ++i) {
assert.eq(a1[i].avgCounter, a1[i]._id, 'agg sharded test avgCounter failed');
@@ -115,7 +96,7 @@ assert.eq(a2[0].total, (nItems / 2) * (1 + nItems), 'agg sharded test counter su
jsTestLog('A group combining all documents into one, averaging a null field.');
assert.eq(aggregateOrdered(db.ts1, [{$group: {_id: null, avg: {$avg: "$missing"}}}]),
- [{_id: null, avg: null}]);
+ [{_id: null, avg: null}]);
jsTestLog('an initial group starts the group in the shards, and combines them in mongos');
var a3 =
@@ -126,19 +107,18 @@ for (i = 0; i < strings.length; ++i) {
}
jsTestLog('a match takes place in the shards; just returning the results from mongos');
-var a4 = aggregateNoOrder(db.ts1,
- [{
- $match: {
- $or: [
- {counter: 55},
- {counter: 1111},
- {counter: 2222},
- {counter: 33333},
- {counter: 99999},
- {counter: 55555}
- ]
- }
- }]);
+var a4 = aggregateNoOrder(db.ts1, [{
+ $match: {
+ $or: [
+ {counter: 55},
+ {counter: 1111},
+ {counter: 2222},
+ {counter: 33333},
+ {counter: 99999},
+ {counter: 55555}
+ ]
+ }
+ }]);
assert.eq(a4.length, 6, tojson(a4));
for (i = 0; i < 6; ++i) {
@@ -192,13 +172,15 @@ function testAvgStdDev() {
jsTestLog('testing $avg and $stdDevPop in sharded $group');
// Note: not using aggregateOrdered since it requires exact results. $stdDevPop can vary
// slightly between runs if a migration occurs. This is why we use assert.close below.
- var res = db.ts1.aggregate([{
- $group: {
- _id: null,
- avg: {$avg: '$counter'},
- stdDevPop: {$stdDevPop: '$counter'},
- }
- }]).toArray();
+ var res = db.ts1
+ .aggregate([{
+ $group: {
+ _id: null,
+ avg: {$avg: '$counter'},
+ stdDevPop: {$stdDevPop: '$counter'},
+ }
+ }])
+ .toArray();
// http://en.wikipedia.org/wiki/Arithmetic_progression#Sum
var avg = (1 + nItems) / 2;
assert.close(res[0].avg, avg, '', 10 /*decimal places*/);
@@ -233,10 +215,7 @@ db.literal.save({dollar: false});
result = aggregateOrdered(
db.literal,
- [{
- $project:
- {_id: 0, cost: {$cond: ['$dollar', {$literal: '$1.00'}, {$literal: '$.99'}]}}
- }]);
+ [{$project: {_id: 0, cost: {$cond: ['$dollar', {$literal: '$1.00'}, {$literal: '$.99'}]}}}]);
assert.eq([{cost: '$.99'}], result);
diff --git a/jstests/aggregation/unwind.js b/jstests/aggregation/unwind.js
index ba6ffa44a86..ffd2a3da9c6 100644
--- a/jstests/aggregation/unwind.js
+++ b/jstests/aggregation/unwind.js
@@ -12,7 +12,6 @@ t.insert({_id: 6, x: 4});
var res = t.aggregate([{$unwind: "$x"}, {$sort: {_id: 1}}]).toArray();
assert.eq(4, res.length);
-assert.eq([1, 2, 3, 4],
- res.map(function(z) {
- return z.x;
- }));
+assert.eq([1, 2, 3, 4], res.map(function(z) {
+ return z.x;
+}));