diff options
-rw-r--r-- | jstests/core/geo_uniqueDocs.js | 3 | ||||
-rw-r--r-- | jstests/core/timeseries/timeseries_internal_bucket_geo_within.js | 5 | ||||
-rw-r--r-- | src/mongo/db/matcher/expression_geo.cpp | 6 |
3 files changed, 13 insertions, 1 deletions
diff --git a/jstests/core/geo_uniqueDocs.js b/jstests/core/geo_uniqueDocs.js index c15c1a35c99..9e0a811e7e7 100644 --- a/jstests/core/geo_uniqueDocs.js +++ b/jstests/core/geo_uniqueDocs.js @@ -41,10 +41,11 @@ assert.eq(2, t.find({locs: {$within: {$box: [[0, 0], [9, 9]], $uniqueDocs: false assert.eq(2, t.find({locs: {$within: {$center: [[5, 5], 7], $uniqueDocs: true}}}).itcount()); assert.eq(2, t.find({locs: {$within: {$center: [[5, 5], 7], $uniqueDocs: false}}}).itcount()); +assert.eq(2, t.find({locs: {$within: {$uniqueDocs: false, $center: [[5, 5], 7]}}}).itcount()); assert.eq(2, t.find({locs: {$within: {$centerSphere: [[5, 5], 1], $uniqueDocs: true}}}).itcount()); assert.eq(2, t.find({locs: {$within: {$centerSphere: [[5, 5], 1], $uniqueDocs: false}}}).itcount()); - +assert.eq(2, t.find({locs: {$within: {$uniqueDocs: true, $centerSphere: [[5, 5], 1]}}}).itcount()); assert.eq( 2, t.find({locs: {$within: {$polygon: [[0, 0], [0, 9], [9, 9]], $uniqueDocs: true}}}).itcount()); diff --git a/jstests/core/timeseries/timeseries_internal_bucket_geo_within.js b/jstests/core/timeseries/timeseries_internal_bucket_geo_within.js index 9c237d8dd77..ffe6fc3774a 100644 --- a/jstests/core/timeseries/timeseries_internal_bucket_geo_within.js +++ b/jstests/core/timeseries/timeseries_internal_bucket_geo_within.js @@ -306,5 +306,10 @@ assert.sameMembers(results, [ }]; err = assert.throws(() => coll.explain().aggregate(pipeline)); assert.eq(err.code, ErrorCodes.BadValue, err); + + // $geoWithin doesn't support multiple shapes. + pipeline = [{$match: {loc: {$geoWithin: {$centerSphere: [[0, 80], 1], $center: [[0, 0], 5]}}}}]; + err = assert.throws(() => coll.explain().aggregate(pipeline)); + assert.eq(err.code, ErrorCodes.BadValue, err); } }()); diff --git a/src/mongo/db/matcher/expression_geo.cpp b/src/mongo/db/matcher/expression_geo.cpp index eb47d3db124..8135e0d9d8e 100644 --- a/src/mongo/db/matcher/expression_geo.cpp +++ b/src/mongo/db/matcher/expression_geo.cpp @@ -79,6 +79,12 @@ Status GeoExpression::parseQuery(const BSONObj& obj) { while (geoIt.more()) { BSONElement elt = geoIt.next(); + // $geoWithin doesn't accept multiple shapes. + if (geoContainer && queryElt.fieldNameStringData() == "$geoWithin"_sd) { + return Status(ErrorCodes::BadValue, + str::stream() << "$geoWithin doesn't accept multiple shapes " + << queryElt.toString()); + } if (elt.fieldNameStringData() == "$uniqueDocs") { // Deprecated "$uniqueDocs" field LOGV2_WARNING(23847, "Deprecated $uniqueDocs option", "query"_attr = redact(obj)); |