jstests/aggregation/sources/densify/partitions.js
// Same as above, but with extra documents in the middle of each partition somewhere.
Same as above, but with extra documents in the middle of each partition somewhere.
Same as above but with extra documents in the middle of each partition somewhere .
function fullTestThree(stepVal = 2) {
    coll.drop();
    let testDocs = [];
    let testExpected = [];
    testDocs.push({val: 0, part: 0});
    testDocs.push({val: 4, part: 0});
    testDocs.push({val: 0, part: 1});
    testDocs.push({val: 5, part: 1});
    testExpected.push({val: 5, part: 1});
    testDocs.push({val: 10, part: 2});
    for (let densifyVal = 0; densifyVal < 11; densifyVal += stepVal) {
        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: stepVal, bounds: "full"}, partitionByFields: ["part"]}
        },
        {$sort: {val: 1, part: 1}}
    ]);
    const resultArray = result.toArray();
    assert(arrayEq(resultArray, testExpected), buildErrorString(resultArray, testExpected));
}
function fullTestThree ( stepVal = 2 ) { coll . drop ( ) ; let testDocs = [ ] ; let testExpected = [ ] ; testDocs . push ( { val : 0 , part : 0 } ) ; testDocs . push ( { val : 4 , part : 0 } ) ; testDocs . push ( { val : 0 , part : 1 } ) ; testDocs . push ( { val : 5 , part : 1 } ) ; testExpected . push ( { val : 5 , part : 1 } ) ; testDocs . push ( { val : 10 , part : 2 } ) ; for ( let densifyVal = 0 ; densifyVal < 11 ; densifyVal += stepVal ) { 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 : stepVal , bounds : "full" } , partitionByFields : [ "part" ] } } , { $sort : { val : 1 , part : 1 } } ] ) ; const resultArray = result . toArray ( ) ; assert ( arrayEq ( resultArray , testExpected ) , buildErrorString ( resultArray , testExpected ) ) ; }
Same as above, but with extra documents in the middle of each partition somewhere.
Same as above but with extra documents in the middle of each partition somewhere .
// Add an initial document.