summaryrefslogtreecommitdiff
path: root/jstests/aggregation
diff options
context:
space:
mode:
authorJames Wahlin <james.wahlin@10gen.com>2017-05-19 17:05:31 -0400
committerJames Wahlin <james@mongodb.com>2017-06-14 08:25:42 -0400
commit99807c88bb8974e077f57859ce8bf1a921f17647 (patch)
treeb7973cdd6e92252ba3af34e4673fa4544a1a53a1 /jstests/aggregation
parent6cb744fb6be51ac18cd75e130598a7b0eb193dd8 (diff)
downloadmongo-99807c88bb8974e077f57859ce8bf1a921f17647.tar.gz
SERVER-28717 Expand $lookup localField when a sub-obj field in an array
Includes: - Cherry pick of commit e56f02ec6de6def5e66d0744a620515e2a82708e - Partial cherry pick of commit d60dd07f3f470b702092b6b54e15586a5177d8a1 pulling in src/mongo/db/pipeline/document_path_support* files and associated SConscript additions
Diffstat (limited to 'jstests/aggregation')
-rw-r--r--jstests/aggregation/sources/lookup/lookup.js (renamed from jstests/aggregation/bugs/server19095.js)57
1 files changed, 52 insertions, 5 deletions
diff --git a/jstests/aggregation/bugs/server19095.js b/jstests/aggregation/sources/lookup/lookup.js
index e55539cedc7..831e91c64be 100644
--- a/jstests/aggregation/bugs/server19095.js
+++ b/jstests/aggregation/sources/lookup/lookup.js
@@ -1,7 +1,6 @@
-// SERVER-19095: Add $lookup aggregation stage.
+// Basic $lookup regression tests.
-// For assertErrorCode.
-load("jstests/aggregation/extras/utils.js");
+load("jstests/aggregation/extras/utils.js"); // For assertErrorCode.
(function() {
"use strict";
@@ -344,9 +343,31 @@ load("jstests/aggregation/extras/utils.js");
expectedResults = [{_id: 0, a: [0, 1, 2], b: [{_id: 0}, {_id: 1}]}];
testPipeline(pipeline, expectedResults, coll);
+ // Basic array corresponding to a single document.
+ coll.drop();
+ assert.writeOK(coll.insert({_id: 0, a: [1]}));
+
+ from.drop();
+ assert.writeOK(from.insert({_id: 0}));
+ assert.writeOK(from.insert({_id: 1}));
+
+ pipeline = [
+ {
+ $lookup: {
+ localField: "a",
+ foreignField: "_id",
+ from: "from",
+ as: "b",
+ }
+ },
+ ];
+ expectedResults = [{_id: 0, a: [1], b: [{_id: 1}]}];
+ testPipeline(pipeline, expectedResults, coll);
+
// Array containing regular expressions.
coll.drop();
assert.writeOK(coll.insert({_id: 0, a: [/a regex/, /^x/]}));
+ assert.writeOK(coll.insert({_id: 1, a: [/^x/]}));
from.drop();
assert.writeOK(from.insert({_id: 0, b: "should not match a regex"}));
@@ -364,8 +385,34 @@ load("jstests/aggregation/extras/utils.js");
}
},
];
- expectedResults =
- [{_id: 0, a: [/a regex/, /^x/], b: [{_id: 2, b: /a regex/}, {_id: 3, b: /^x/}]}];
+ expectedResults = [
+ {_id: 0, a: [/a regex/, /^x/], b: [{_id: 2, b: /a regex/}, {_id: 3, b: /^x/}]},
+ {_id: 1, a: [/^x/], b: [{_id: 3, b: /^x/}]}
+ ];
+ testPipeline(pipeline, expectedResults, coll);
+
+ // 'localField' references a field within an array of sub-objects.
+ coll.drop();
+ assert.writeOK(coll.insert({_id: 0, a: [{b: 1}, {b: 2}]}));
+
+ from.drop();
+ assert.writeOK(from.insert({_id: 0}));
+ assert.writeOK(from.insert({_id: 1}));
+ assert.writeOK(from.insert({_id: 2}));
+ assert.writeOK(from.insert({_id: 3}));
+
+ pipeline = [
+ {
+ $lookup: {
+ localField: "a.b",
+ foreignField: "_id",
+ from: "from",
+ as: "c",
+ }
+ },
+ ];
+
+ expectedResults = [{"_id": 0, "a": [{"b": 1}, {"b": 2}], "c": [{"_id": 1}, {"_id": 2}]}];
testPipeline(pipeline, expectedResults, coll);
//