jstests/sharding/query/aggregates_during_balancing.js
// test sort + limit (using random to pull from both shards)
test sort + limit (using random to pull from both shards)
test sort + limit ( using random to pull from both shards )
function testSortLimit(limit, direction) {
    jsTestLog('Testing $sort with $limit: ' + limit + ', ' + direction);
    var from_cursor =
        database.ts1.find({}, {random: 1, _id: 0}).sort({random: direction}).limit(limit).toArray();
    var from_agg =
        database.ts1
            .aggregate(
                [{$project: {random: 1, _id: 0}}, {$sort: {random: direction}}, {$limit: limit}])
            .toArray();
    assert.eq(from_cursor, from_agg);
}
function testSortLimit ( limit , direction ) { jsTestLog ( 'Testing $sort with $limit: ' + limit + ', ' + direction ) ; var from_cursor = database . ts1 . find ( { } , { random : 1 , _id : 0 } ) . sort ( { random : direction } ) . limit ( limit ) . toArray ( ) ; var from_agg = database . ts1 . aggregate ( [ { $project : { random : 1 , _id : 0 } } , { $sort : { random : direction } } , { $limit : limit } ] ) . toArray ( ) ; assert . eq ( from_cursor , from_agg ) ; }
test sort + limit (using random to pull from both shards)
test sort + limit ( using random to pull from both shards )