jstests/aggregation/sources/densify/partitions.js
// Three partitions, each with different documents w/respect to the range.
Three partitions, each with different documents w/respect to the range.
Three partitions each with different documents w / respect to the range .
function rangeTestTwo() {
    coll.drop();
    let testDocs = [];
    let testExpected = [];
    testDocs.push({val: 0, part: 0});
    testExpected.push({val: 0, part: 0});
    testDocs.push({val: 5, part: 1});
    testExpected.push({val: 5, part: 1});
    testDocs.push({val: 10, part: 2});
    testExpected.push({val: 10, part: 2});
    for (let densifyVal = 4; densifyVal < 8; densifyVal += 2) {
        for (let partitionVal = 0; partitionVal <= 2; partitionVal++) {
            testExpected.push({val: densifyVal, part: partitionVal});
        }
    }
    assert.commandWorked(coll.insert(testDocs));
    let result = coll.aggregate([
        {$project: {_id: 0}},
        {$densify: {field: "val", range: {step: 2, bounds: [4, 8]}, partitionByFields: ["part"]}},
        {$sort: {val: 1, part: 1}}
    ]);
    const resultArray = result.toArray();
    assert(arrayEq(resultArray, testExpected), buildErrorString(resultArray, testExpected));
}
function rangeTestTwo ( ) { coll . drop ( ) ; let testDocs = [ ] ; let testExpected = [ ] ; testDocs . push ( { val : 0 , part : 0 } ) ; testExpected . push ( { val : 0 , part : 0 } ) ; testDocs . push ( { val : 5 , part : 1 } ) ; testExpected . push ( { val : 5 , part : 1 } ) ; testDocs . push ( { val : 10 , part : 2 } ) ; testExpected . push ( { val : 10 , part : 2 } ) ; for ( let densifyVal = 4 ; densifyVal < 8 ; densifyVal += 2 ) { for ( let partitionVal = 0 ; partitionVal <= 2 ; partitionVal ++ ) { testExpected . push ( { val : densifyVal , part : partitionVal } ) ; } } assert . commandWorked ( coll . insert ( testDocs ) ) ; let result = coll . aggregate ( [ { $project : { _id : 0 } } , { $densify : { field : "val" , range : { step : 2 , bounds : [ 4 , 8 ] } , partitionByFields : [ "part" ] } } , { $sort : { val : 1 , part : 1 } } ] ) ; const resultArray = result . toArray ( ) ; assert ( arrayEq ( resultArray , testExpected ) , buildErrorString ( resultArray , testExpected ) ) ; }
Three partitions, each with different documents w/respect to the range.
Three partitions each with different documents w / respect to the range .