jstests/ssl/libs/ssl_helpers.js
/**
 * Test that $lookup works with a sharded source collection. This is tested because of
 * the connections opened between mongos/shards and between the shards themselves.
 */
Test that $lookup works with a sharded source collection. This is tested because of
the connections opened between mongos/shards and between the shards themselves.
Test that $lookup works with a sharded source collection . This is tested because of the connections opened between mongos / shards and between the shards themselves .
function testShardedLookup(shardingTest) {
    var st = shardingTest;
    assert(st.adminCommand({enableSharding: "lookupTest"}),
           "error enabling sharding for this configuration");
    assert(st.adminCommand({shardCollection: "lookupTest.foo", key: {_id: "hashed"}}),
           "error sharding collection for this configuration");
    var lookupdb = st.getDB("lookupTest");
    var fooBulk = lookupdb.foo.initializeUnorderedBulkOp();
    var barBulk = lookupdb.bar.initializeUnorderedBulkOp();
    var lookupShouldReturn = [];
    for (var i = 0; i < 64; i++) {
        fooBulk.insert({_id: i});
        barBulk.insert({_id: i});
        lookupShouldReturn.push({_id: i, bar_docs: [{_id: i}]});
    }
    assert.commandWorked(fooBulk.execute());
    assert.commandWorked(barBulk.execute());
    var docs =
        lookupdb.foo
            .aggregate([
                {$sort: {_id: 1}},
                {$lookup: {from: "bar", localField: "_id", foreignField: "_id", as: "bar_docs"}}
            ])
            .toArray();
    assert.eq(lookupShouldReturn, docs, "error $lookup failed in this configuration");
    assert.commandWorked(lookupdb.dropDatabase());
}
function testShardedLookup ( shardingTest ) { var st = shardingTest ; assert ( st . adminCommand ( { enableSharding : "lookupTest" } ) , "error enabling sharding for this configuration" ) ; assert ( st . adminCommand ( { shardCollection : "lookupTest.foo" , key : { _id : "hashed" } } ) , "error sharding collection for this configuration" ) ; var lookupdb = st . getDB ( "lookupTest" ) ; var fooBulk = lookupdb . foo . initializeUnorderedBulkOp ( ) ; var barBulk = lookupdb . bar . initializeUnorderedBulkOp ( ) ; var lookupShouldReturn = [ ] ; for ( var i = 0 ; i < 64 ; i ++ ) { fooBulk . insert ( { _id : i } ) ; barBulk . insert ( { _id : i } ) ; lookupShouldReturn . push ( { _id : i , bar_docs : [ { _id : i } ] } ) ; } assert . commandWorked ( fooBulk . execute ( ) ) ; assert . commandWorked ( barBulk . execute ( ) ) ; var docs = lookupdb . foo . aggregate ( [ { $sort : { _id : 1 } } , { $lookup : { from : "bar" , localField : "_id" , foreignField : "_id" , as : "bar_docs" } } ] ) . toArray ( ) ; assert . eq ( lookupShouldReturn , docs , "error $lookup failed in this configuration" ) ; assert . commandWorked ( lookupdb . dropDatabase ( ) ) ; }
Test that $lookup works with a sharded source collection.
Test that $lookup works with a sharded source collection .
// insert a few docs to ensure there are documents on multiple shards.