summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric Cox <eric.cox@mongodb.com>2021-09-14 15:05:18 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2021-09-14 15:50:06 +0000
commit85cf0f4bdb5763514df90653a677cf8fa0100305 (patch)
tree609e1a6334a7233c38eb70dc66dd73541a6229e5
parent9cbf52051d506a029546c1e7e28a5f77afd8bd46 (diff)
downloadmongo-85cf0f4bdb5763514df90653a677cf8fa0100305.tar.gz
SERVER-57938 Skip validation for stored geometry if a 2dsphere index exists
-rw-r--r--jstests/core/geo_s2intersection.js7
-rw-r--r--src/mongo/db/exec/geo_near.cpp4
-rw-r--r--src/mongo/db/geo/geometry_container.cpp3
-rw-r--r--src/mongo/db/geo/geoparser.cpp5
4 files changed, 13 insertions, 6 deletions
diff --git a/jstests/core/geo_s2intersection.js b/jstests/core/geo_s2intersection.js
index 3c841d85f50..958da005a9f 100644
--- a/jstests/core/geo_s2intersection.js
+++ b/jstests/core/geo_s2intersection.js
@@ -1,3 +1,9 @@
+/**
+ * Tests $geoIntersect basic functionality.
+ */
+(function() {
+"use strict";
+
var t = db.geo_s2intersectinglines;
t.drop();
t.createIndex({geo: "2dsphere"});
@@ -158,3 +164,4 @@ assert.eq(result.count(), 1);
// two $geoIntersects should as well.
result = t.find({$and: [{a: {$geoIntersects: firstPoint}}, {a: {$geoIntersects: secondPoint}}]});
assert.eq(result.count(), 1);
+})();
diff --git a/src/mongo/db/exec/geo_near.cpp b/src/mongo/db/exec/geo_near.cpp
index 0ce4f9ab856..fdb731ff033 100644
--- a/src/mongo/db/exec/geo_near.cpp
+++ b/src/mongo/db/exec/geo_near.cpp
@@ -77,7 +77,9 @@ static double computeGeoNearDistance(const GeoNearParams& nearParams, WorkingSet
CRS queryCRS = nearParams.nearQuery->centroid->crs;
- // Extract all the geometries out of this document for the near query
+ // Extract all the geometries out of this document for the near query. Note that the NearStage
+ // stage can only be run with an existing index. Therefore, it is always safe to skip geometry
+ // validation.
std::vector<std::unique_ptr<StoredGeometry>> geometries;
StoredGeometry::extractGeometries(
member->doc.value().toBson(), nearParams.nearQuery->field, &geometries, true);
diff --git a/src/mongo/db/geo/geometry_container.cpp b/src/mongo/db/geo/geometry_container.cpp
index e4f18636b14..03a97ef86b0 100644
--- a/src/mongo/db/geo/geometry_container.cpp
+++ b/src/mongo/db/geo/geometry_container.cpp
@@ -1339,9 +1339,6 @@ StoredGeometry* StoredGeometry::parseFrom(const BSONElement& element, bool skipV
return nullptr;
std::unique_ptr<StoredGeometry> stored(new StoredGeometry);
-
- // GeoNear stage can only be run with an existing index
- // Therefore, it is always safe to skip geometry validation
if (!stored->geometry.parseFromStorage(element, skipValidation).isOK())
return nullptr;
stored->element = element;
diff --git a/src/mongo/db/geo/geoparser.cpp b/src/mongo/db/geo/geoparser.cpp
index bf4888bbf5b..ea97c706851 100644
--- a/src/mongo/db/geo/geoparser.cpp
+++ b/src/mongo/db/geo/geoparser.cpp
@@ -189,7 +189,8 @@ static Status parseGeoJSONPolygonCoordinates(const BSONElement& elem,
loops.push_back(std::make_unique<S2Loop>(points));
S2Loop* loop = loops.back().get();
- // Check whether this loop is valid.
+ // Check whether this loop is valid if vaildation hasn't been already done on 2dSphere index
+ // insertion which is controlled by the 'skipValidation' flag.
// 1. At least 3 vertices.
// 2. All vertices must be unit length. Guaranteed by parsePoints().
// 3. Loops are not allowed to have any duplicate vertices.
@@ -202,7 +203,7 @@ static Status parseGeoJSONPolygonCoordinates(const BSONElement& elem,
// Check the first loop must be the exterior ring and any others must be
// interior rings or holes.
- if (loops.size() > 1 && !loops[0]->Contains(loop)) {
+ if (!skipValidation && loops.size() > 1 && !loops[0]->Contains(loop)) {
return BAD_VALUE(
"Secondary loops not contained by first exterior loop - "
"secondary loops must be holes: "