summaryrefslogtreecommitdiff
path: root/jstests
diff options
context:
space:
mode:
authorDavid Storch <david.storch@10gen.com>2016-10-03 11:17:13 -0400
committerDavid Storch <david.storch@10gen.com>2016-10-03 16:13:51 -0400
commit8758a5c7be68effbc4a1f857787bfb7b201c6389 (patch)
tree4880b453167dcada211c278dbc34ff095e31d81c /jstests
parentb8a5742ef7623640eb6977f14e25649bad661208 (diff)
downloadmongo-8758a5c7be68effbc4a1f857787bfb7b201c6389.tar.gz
SERVER-25038 add LiteParsedPipeline
This provides a way to do pre-parse validity checks. Full parsing of the Pipeline must be done under the collection lock, when the collation is known.
Diffstat (limited to 'jstests')
-rw-r--r--jstests/aggregation/bugs/server19095.js9
-rw-r--r--jstests/aggregation/bugs/server6045.js8
-rw-r--r--jstests/aggregation/bugs/server6861.js8
-rw-r--r--jstests/aggregation/sources/bucket/collation_bucket.js49
-rw-r--r--jstests/aggregation/sources/graphLookup/error.js20
-rw-r--r--jstests/views/views_collation.js12
6 files changed, 92 insertions, 14 deletions
diff --git a/jstests/aggregation/bugs/server19095.js b/jstests/aggregation/bugs/server19095.js
index 875a7d16a9d..e55539cedc7 100644
--- a/jstests/aggregation/bugs/server19095.js
+++ b/jstests/aggregation/bugs/server19095.js
@@ -375,7 +375,7 @@ load("jstests/aggregation/extras/utils.js");
// All four fields must be specified.
assertErrorCode(coll, [{$lookup: {foreignField: "b", from: "from", as: "same"}}], 4572);
assertErrorCode(coll, [{$lookup: {localField: "a", from: "from", as: "same"}}], 4572);
- assertErrorCode(coll, [{$lookup: {localField: "a", foreignField: "b", as: "same"}}], 4572);
+ assertErrorCode(coll, [{$lookup: {localField: "a", foreignField: "b", as: "same"}}], 40320);
assertErrorCode(
coll, [{$lookup: {localField: "a", foreignField: "b", from: "from"}}], 4572);
@@ -385,12 +385,15 @@ load("jstests/aggregation/extras/utils.js");
assertErrorCode(
coll, [{$lookup: {localField: "a", foreignField: 1, from: "from", as: "as"}}], 4570);
assertErrorCode(
- coll, [{$lookup: {localField: "a", foreignField: "b", from: 1, as: "as"}}], 4570);
+ coll, [{$lookup: {localField: "a", foreignField: "b", from: 1, as: "as"}}], 40321);
assertErrorCode(
coll, [{$lookup: {localField: "a", foreignField: "b", from: "from", as: 1}}], 4570);
+ // The foreign collection must be a valid namespace.
+ assertErrorCode(
+ coll, [{$lookup: {localField: "a", foreignField: "b", from: "", as: "as"}}], 40322);
// $lookup's field must be an object.
- assertErrorCode(coll, [{$lookup: "string"}], 4569);
+ assertErrorCode(coll, [{$lookup: "string"}], 40319);
}
// Run tests on single node.
diff --git a/jstests/aggregation/bugs/server6045.js b/jstests/aggregation/bugs/server6045.js
index 852a8bdc093..dc250ca9516 100644
--- a/jstests/aggregation/bugs/server6045.js
+++ b/jstests/aggregation/bugs/server6045.js
@@ -27,10 +27,10 @@ db.agg.insert({key: "string", value: 17});
db.agg.insert({key: "yarn", value: 42});
// As pipeline
-assertErrorCode(db.agg, [{}], 16435);
+assertErrorCode(db.agg, [{}], 40323);
// Start of pipeline
-assertErrorCode(db.agg, [{$project: {value: 1}}, {}], 16435);
+assertErrorCode(db.agg, [{$project: {value: 1}}, {}], 40323);
// End of pipeline
-assertErrorCode(db.agg, [{}, {$project: {value: 1}}], 16435);
+assertErrorCode(db.agg, [{}, {$project: {value: 1}}], 40323);
// Middle of pipeline
-assertErrorCode(db.agg, [{$project: {value: 1}}, {}, {$project: {value: 1}}], 16435);
+assertErrorCode(db.agg, [{$project: {value: 1}}, {}, {$project: {value: 1}}], 40323);
diff --git a/jstests/aggregation/bugs/server6861.js b/jstests/aggregation/bugs/server6861.js
index 28d19445241..e6748bd07da 100644
--- a/jstests/aggregation/bugs/server6861.js
+++ b/jstests/aggregation/bugs/server6861.js
@@ -19,9 +19,9 @@ function assertResult(result, expression) {
assertResult([{a: 1}], {$project: {_id: 0, a: 1}});
// Incorrect number of fields.
-assertCode(16435, {});
-assertCode(16435, {$project: {_id: 0, a: 1}, $group: {_id: 0}});
-assertCode(16435, {$project: {_id: 0, a: 1}, $group: {_id: 0}, $sort: {a: 1}});
+assertCode(40323, {});
+assertCode(40323, {$project: {_id: 0, a: 1}, $group: {_id: 0}});
+assertCode(40323, {$project: {_id: 0, a: 1}, $group: {_id: 0}, $sort: {a: 1}});
// Invalid stage specification.
-assertCode(16436, {$noSuchStage: {a: 1}});
+assertCode(40324, {$noSuchStage: {a: 1}});
diff --git a/jstests/aggregation/sources/bucket/collation_bucket.js b/jstests/aggregation/sources/bucket/collation_bucket.js
index 8fb791e0901..b21ae778569 100644
--- a/jstests/aggregation/sources/bucket/collation_bucket.js
+++ b/jstests/aggregation/sources/bucket/collation_bucket.js
@@ -49,4 +49,53 @@
assert.throws(
() => coll.aggregate([{$bucket: {groupBy: "$num", boundaries: ["1", "10", "100", "1000"]}}],
{collation: {locale: "simple"}}));
+
+ // Test that $bucket rejects boundaries that are not sorted according to the collation.
+ assert.throws(
+ () => coll.aggregate([{$bucket: {groupBy: "$num", boundaries: ["100", "20", "4"]}}]));
+
+ assert.throws(() =>
+ coll.aggregate([{$bucket: {groupBy: "$num", boundaries: ["4", "20", "100"]}}],
+ {collation: {locale: "simple"}}));
+
+ // Test that $bucket rejects a default value that falls within the boundaries.
+ assert.throws(
+ () => coll.aggregate(
+ [{$bucket: {groupBy: "$num", boundaries: ["1", "10", "100"], default: "40"}}]));
+
+ assert.throws(() => coll.aggregate(
+ [{$bucket: {groupBy: "$num", boundaries: ["100", "999"], default: "2"}}],
+ {collation: {locale: "simple"}}));
+
+ // Test that $bucket accepts a default value that falls outside the boundaries according to the
+ // collation.
+ results =
+ coll.aggregate([{
+ $bucket: {
+ groupBy: "$num",
+ boundaries: ["100", "999"],
+ default: "2" // Would fall between 100 and 999 if using the simple collation.
+ }
+ }])
+ .toArray();
+ assert.eq(2, results.length);
+ assert.eq({_id: "2", count: 6}, results[0]);
+ assert.eq({_id: "100", count: 3}, results[1]); // "100", "200", and "500".
+
+ results =
+ coll.aggregate(
+ [{
+ $bucket: {
+ groupBy: "$num",
+ boundaries: ["1", "19999"], // Will include all numbers that start with "1"
+ default: "2" // Would fall between boundaries if using the
+ // collection-default collation with numeric
+ // ordering.
+ }
+ }],
+ {collation: {locale: "simple"}})
+ .toArray();
+ assert.eq(2, results.length);
+ assert.eq({_id: "1", count: 3}, results[0]); // "1", "10", and "100".
+ assert.eq({_id: "2", count: 6}, results[1]);
})();
diff --git a/jstests/aggregation/sources/graphLookup/error.js b/jstests/aggregation/sources/graphLookup/error.js
index 2728e1abd75..a686fb30945 100644
--- a/jstests/aggregation/sources/graphLookup/error.js
+++ b/jstests/aggregation/sources/graphLookup/error.js
@@ -9,7 +9,10 @@ load("jstests/aggregation/extras/utils.js"); // For "assertErrorCode".
local.drop();
local.insert({});
- var pipeline = {
+ var pipeline = {$graphLookup: 4};
+ assertErrorCode(local, pipeline, 40327, "$graphLookup spec must be an object");
+
+ pipeline = {
$graphLookup: {
from: "foreign",
startWith: {$literal: 0},
@@ -54,7 +57,18 @@ load("jstests/aggregation/extras/utils.js"); // For "assertErrorCode".
as: "output"
}
};
- assertErrorCode(local, pipeline, 40103, "from must be a string");
+ assertErrorCode(local, pipeline, 40329, "from must be a string");
+
+ pipeline = {
+ $graphLookup: {
+ from: "",
+ startWith: {$literal: 0},
+ connectToField: "a",
+ connectFromField: "b",
+ as: "output"
+ }
+ };
+ assertErrorCode(local, pipeline, 40330, "from must be a valid namespace");
pipeline = {
$graphLookup: {
@@ -201,7 +215,7 @@ load("jstests/aggregation/extras/utils.js"); // For "assertErrorCode".
$graphLookup:
{startWith: {$literal: 0}, connectToField: "a", connectFromField: "b", as: "output"}
};
- assertErrorCode(local, pipeline, 40105, "from was not specified");
+ assertErrorCode(local, pipeline, 40328, "from was not specified");
// restrictSearchWithMatch must be a valid match expression.
pipeline = {
diff --git a/jstests/views/views_collation.js b/jstests/views/views_collation.js
index 4dfe3e59d55..04abf106292 100644
--- a/jstests/views/views_collation.js
+++ b/jstests/views/views_collation.js
@@ -77,14 +77,26 @@
viewsDB.runCommand({aggregate: "filView", pipeline: [], collation: {locale: "en"}}),
ErrorCodes.OptionNotSupportedOnView);
assert.commandFailedWithCode(
+ viewsDB.runCommand({aggregate: "filView", pipeline: [], collation: {locale: "simple"}}),
+ ErrorCodes.OptionNotSupportedOnView);
+ assert.commandFailedWithCode(
viewsDB.runCommand({find: "filView", collation: {locale: "fr"}}),
ErrorCodes.OptionNotSupportedOnView);
assert.commandFailedWithCode(
+ viewsDB.runCommand({find: "filView", collation: {locale: "simple"}}),
+ ErrorCodes.OptionNotSupportedOnView);
+ assert.commandFailedWithCode(
viewsDB.runCommand({count: "filView", collation: {locale: "zh"}}),
ErrorCodes.OptionNotSupportedOnView);
assert.commandFailedWithCode(
+ viewsDB.runCommand({count: "filView", collation: {locale: "simple"}}),
+ ErrorCodes.OptionNotSupportedOnView);
+ assert.commandFailedWithCode(
viewsDB.runCommand({distinct: "filView", key: "x", collation: {locale: "es"}}),
ErrorCodes.OptionNotSupportedOnView);
+ assert.commandFailedWithCode(
+ viewsDB.runCommand({distinct: "filView", key: "x", collation: {locale: "simple"}}),
+ ErrorCodes.OptionNotSupportedOnView);
const lookupSimpleView = {
$lookup: {from: "simpleView", localField: "x", foreignField: "x", as: "result"}