summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMaddie Zechar <mez2113@columbia.edu>2022-09-01 17:15:10 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2022-09-01 18:52:35 +0000
commitd683e42c67a5a75b7ba16491e2b168bcb6a286ce (patch)
treed43c30d2da67c007dc739d5ed97572bb59c760e4
parent02ca47e1d1937fe0ef56385ea67e3f5698c57d6c (diff)
downloadmongo-d683e42c67a5a75b7ba16491e2b168bcb6a286ce.tar.gz
SERVER-62492 $geoWithin shouldn't accept multiple shapes
-rw-r--r--jstests/core/geo_uniqueDocs.js3
-rw-r--r--jstests/core/timeseries/timeseries_internal_bucket_geo_within.js5
-rw-r--r--src/mongo/db/matcher/expression_geo.cpp6
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));