summaryrefslogtreecommitdiff
path: root/jstests
diff options
context:
space:
mode:
authorCharlie Swanson <charlie.swanson@mongodb.com>2016-10-24 15:45:30 -0400
committerCharlie Swanson <charlie.swanson@mongodb.com>2016-10-25 10:15:52 -0400
commit6822a010ac581ed5321a40dcfec80b369870dccb (patch)
treea132e3b7affb9418da71122043935e5104adcadc /jstests
parent913a092022f98fc8eb5a035e515cc2cd9908443a (diff)
downloadmongo-6822a010ac581ed5321a40dcfec80b369870dccb.tar.gz
SERVER-25137 Ensure $graphLookup succeeds on non-existent collections
Diffstat (limited to 'jstests')
-rw-r--r--jstests/aggregation/sources/graphLookup/basic.js35
1 files changed, 35 insertions, 0 deletions
diff --git a/jstests/aggregation/sources/graphLookup/basic.js b/jstests/aggregation/sources/graphLookup/basic.js
index 15c8ef85e22..63b2a63f95a 100644
--- a/jstests/aggregation/sources/graphLookup/basic.js
+++ b/jstests/aggregation/sources/graphLookup/basic.js
@@ -10,6 +10,41 @@
local.drop();
foreign.drop();
+ // Ensure a $graphLookup works even if one of the involved collections doesn't exist.
+ const basicGraphLookup = {
+ $graphLookup: {
+ from: "foreign",
+ startWith: "$starting",
+ connectFromField: "from",
+ connectToField: "to",
+ as: "results"
+ }
+ };
+
+ assert.eq(
+ local.aggregate([basicGraphLookup]).toArray().length,
+ 0,
+ "expected an empty result set for a $graphLookup with non-existent local and foreign " +
+ "collections");
+
+ assert.writeOK(foreign.insert({}));
+
+ assert.eq(local.aggregate([basicGraphLookup]).toArray().length,
+ 0,
+ "expected an empty result set for a $graphLookup on a non-existent local collection");
+
+ local.drop();
+ foreign.drop();
+
+ assert.writeOK(local.insert({_id: 0}));
+
+ assert.eq(local.aggregate([basicGraphLookup]).toArray(),
+ [{_id: 0, results: []}],
+ "expected $graphLookup to succeed with a non-existent foreign collection");
+
+ local.drop();
+ foreign.drop();
+
var bulk = foreign.initializeUnorderedBulkOp();
for (var i = 0; i < 100; i++) {
bulk.insert({_id: i, neighbors: [i - 1, i + 1]});