diff options
Diffstat (limited to 'jstests/sharding/graph_lookup.js')
-rw-r--r-- | jstests/sharding/graph_lookup.js | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/jstests/sharding/graph_lookup.js b/jstests/sharding/graph_lookup.js new file mode 100644 index 00000000000..421a2a4acf6 --- /dev/null +++ b/jstests/sharding/graph_lookup.js @@ -0,0 +1,35 @@ +// Test aggregating a sharded collection while using $graphLookup on an unsharded collection. +(function() { + 'use strict'; + + const st = new ShardingTest({shards: 2, rs: {nodes: 1}}); + + assert.commandWorked(st.s0.adminCommand({enablesharding: "test"})); + assert.commandWorked(st.s0.adminCommand({shardCollection: "test.foo", key: {_id: "hashed"}})); + + let db = st.s0.getDB("test"); + + assert.writeOK(db.foo.insert([{}, {}, {}, {}])); + assert.writeOK(db.bar.insert({_id: 1, x: 1})); + + const res = db.foo + .aggregate([{ + $graphLookup: { + from: "bar", + startWith: {$literal: 1}, + connectFromField: "x", + connectToField: "_id", + as: "res" + } + }]) + .toArray(); + + assert.eq(res.length, 4); + res.forEach(function(c) { + assert.eq(c.res.length, 1); + assert.eq(c.res[0]._id, 1); + assert.eq(c.res[0].x, 1); + }); + + st.stop(); +})(); |