jstests/aggregation/bugs/server7781.js
/**
 * Tests the output of the $geoNear command. This function expects a document with the following
 * fields:
 *   - 'geoNearSpec' is the specification for a $geoNear aggregation stage.
 *   - 'limit' is an integer limiting the number of pipeline results.
 *   - 'batchSize', if specified, is the batchSize to use for the aggregation.
 */
Tests the output of the $geoNear command. This function expects a document with the following
fields:
- 'geoNearSpec' is the specification for a $geoNear aggregation stage.
- 'limit' is an integer limiting the number of pipeline results.
- 'batchSize', if specified, is the batchSize to use for the aggregation.
Tests the output of the $geoNear command . This function expects a document with the following fields : - ' geoNearSpec ' is the specification for a $geoNear aggregation stage . - ' limit ' is an integer limiting the number of pipeline results . - ' batchSize ' if specified is the batchSize to use for the aggregation .
function testGeoNearStageOutput({geoNearSpec, limit, batchSize}) {
    const aggOptions = batchSize ? {batchSize: batchSize} : {};
    const result =
        db[coll].aggregate([{$geoNear: geoNearSpec}, {$limit: limit}], aggOptions).toArray();
    const errmsg = () => tojson(result);
    assert.eq(result.length, limit, errmsg);
    result.reduce((lastDist, curDoc) => {
        const curDist = curDoc[kDistanceField];
        assert.lte(lastDist, curDist, errmsg);
        const computed = Geo.sphereDistance(geoNearSpec["near"], curDoc[kIncludeLocsField]);
        assert.close(computed, curDist, errmsg);
        return curDist;
    }, 0);
}
function testGeoNearStageOutput ( { geoNearSpec , limit , batchSize } ) { const aggOptions = batchSize ? { batchSize : batchSize } : { } ; const result = db [ coll ] . aggregate ( [ { $geoNear : geoNearSpec } , { $limit : limit } ] , aggOptions ) . toArray ( ) ; const errmsg = ( ) => tojson ( result ) ; assert . eq ( result . length , limit , errmsg ) ; result . reduce ( ( lastDist , curDoc ) => { const curDist = curDoc [ kDistanceField ] ; assert . lte ( lastDist , curDist , errmsg ) ; const computed = Geo . sphereDistance ( geoNearSpec [ "near" ] , curDoc [ kIncludeLocsField ] ) ; assert . close ( computed , curDist , errmsg ) ; return curDist ; } , 0 ) ; }
Tests the output of the $geoNear command.
Tests the output of the $geoNear command .
// Verify that we got the expected number of results. // Run though the array, checking for proper sort order and sane computed distances. // Verify that distances are in increasing order. // Verify that the computed distance is correct.