diff options
author | Kyle Suarez <kyle.suarez@mongodb.com> | 2018-06-18 23:34:49 -0400 |
---|---|---|
committer | Kyle Suarez <kyle.suarez@mongodb.com> | 2018-06-18 23:34:49 -0400 |
commit | 7bc7864fc042b69d36a88c6839c5dd5b4eb20693 (patch) | |
tree | e103e752e5d708aa22dca3ae99ef269d79a5d917 /jstests/core/json_schema | |
parent | 7c89f48c4f1f1e3ede2931ab602fa118281530a2 (diff) | |
download | mongo-7bc7864fc042b69d36a88c6839c5dd5b4eb20693.tar.gz |
SERVER-35043, SERVER-22949: move geoNear implementation into aggregation
This commit removes the geoNear command and moves its implementation
into the aggregation framework. Users should use the aggregate command
with a $geoNear stage.
The implementation rewrite additionally removes the limit in the
$geoNear aggregation stage. To limit the number of results, use a $limit
stage.
Diffstat (limited to 'jstests/core/json_schema')
-rw-r--r-- | jstests/core/json_schema/misc_validation.js | 45 |
1 files changed, 26 insertions, 19 deletions
diff --git a/jstests/core/json_schema/misc_validation.js b/jstests/core/json_schema/misc_validation.js index ede7b55f55d..c8f5fcaf54b 100644 --- a/jstests/core/json_schema/misc_validation.js +++ b/jstests/core/json_schema/misc_validation.js @@ -50,18 +50,23 @@ coll.count({$jsonSchema: invalidSchema}); }); - // Test that an invalid $jsonSchema fails to parse in a geoNear command. + // Test that an invalid $jsonSchema fails to parse in a $geoNear query. assert.commandWorked(coll.createIndex({geo: "2dsphere"})); let res = testDB.runCommand({ - geoNear: coll.getName(), - near: [30, 40], - spherical: true, - query: {$jsonSchema: invalidSchema} + aggregate: coll.getName(), + cursor: {}, + pipeline: [{ + $geoNear: { + near: [30, 40], + distanceField: "dis", + query: {$jsonSchema: invalidSchema}, + } + }], }); - assert.commandFailed(res); + assert.commandFailedWithCode(res, ErrorCodes.FailedToParse); assert.neq(-1, - res.errmsg.indexOf("Can't parse filter"), - "geoNear command failed for a reason other than invalid query"); + res.errmsg.indexOf("Unknown $jsonSchema keyword"), + `$geoNear failed for a reason other than invalid query: ${tojson(res)}`); // Test that an invalid $jsonSchema fails to parse in a distinct command. assert.throws(function() { @@ -83,21 +88,23 @@ assert.eq(1, coll.count({$jsonSchema: {properties: {a: {type: "number"}, b: {type: "string"}}}})); - // Test that a valid $jsonSchema is legal in a geoNear command. + // Test that a valid $jsonSchema is legal in a $geoNear stage. const point = {type: "Point", coordinates: [31.0, 41.0]}; assert.writeOK(coll.insert({geo: point, a: 1})); assert.writeOK(coll.insert({geo: point, a: 0})); assert.commandWorked(coll.createIndex({geo: "2dsphere"})); - res = testDB.runCommand({ - geoNear: coll.getName(), - near: [30, 40], - spherical: true, - includeLocs: true, - query: {$jsonSchema: {properties: {a: {minimum: 1}}}} - }); - assert.commandWorked(res); - assert.eq(1, res.results.length); - assert.eq(res.results[0].loc, point); + res = coll.aggregate({ + $geoNear: { + near: [30, 40], + spherical: true, + query: {$jsonSchema: {properties: {a: {minimum: 1}}}}, + distanceField: "dis", + includeLocs: "loc", + } + }) + .toArray(); + assert.eq(1, res.length, tojson(res)); + assert.eq(res[0].loc, point, tojson(res)); // Test that a valid $jsonSchema is legal in a distinct command. coll.drop(); |