summaryrefslogtreecommitdiff
path: root/jstests/sharding/graph_lookup.js
blob: 421a2a4acf6cba48a1b7713139d426882d973779 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
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();
})();