summaryrefslogtreecommitdiff
path: root/src/mongo/db/geo
diff options
context:
space:
mode:
authorMax Hirschhorn <max.hirschhorn@mongodb.com>2016-06-03 13:26:35 -0400
committerMax Hirschhorn <max.hirschhorn@mongodb.com>2016-06-03 13:26:35 -0400
commitcecbe424d32cbb475d9b0384d29b98a9fba9c89f (patch)
tree0ce2632b078fee8865f15a56cf07c684a8260c21 /src/mongo/db/geo
parent8900002b731358b0beedadb2ceb4e3156de402b6 (diff)
downloadmongo-cecbe424d32cbb475d9b0384d29b98a9fba9c89f.tar.gz
SERVER-23114 Move functions involving dotted paths to separate library.
The ability to specify a dotted path (e.g. "a.b") to traverse through embedded objects and array elements isn't defined in the BSON specification and so it doesn't belong in our BSON library. The following functions have been defined within a 'dotted_path_support' namespace and accept an additional BSONObj as their first argument to replace the associated method on the BSONObj class. - extractElementAtPath() is functionally equivalent to BSONObj::getFieldDotted(). - extractElementAtPathOrArrayAlongPath() is functionally equivalent to BSONObj::getFieldDottedOrArray(). - extractAllElementsAlongPath() is functionally equivalent to BSONObj::getFieldsDotted(). - extractElementsBasedOnTemplate() is functionally equivalent to BSONObj::extractFields(). - compareObjectsAccordingToSort() is functionally equivalent to BSONObj::woSortOrder().
Diffstat (limited to 'src/mongo/db/geo')
-rw-r--r--src/mongo/db/geo/SConscript1
-rw-r--r--src/mongo/db/geo/geoparser.cpp13
2 files changed, 9 insertions, 5 deletions
diff --git a/src/mongo/db/geo/SConscript b/src/mongo/db/geo/SConscript
index 9c8e13d1268..ca2d94c7349 100644
--- a/src/mongo/db/geo/SConscript
+++ b/src/mongo/db/geo/SConscript
@@ -16,6 +16,7 @@ env.Library("geoparser", [ "geoparser.cpp",
"geometry_container.cpp" ],
LIBDEPS = [ "geometry",
"$BUILD_DIR/mongo/base",
+ "$BUILD_DIR/mongo/db/bson/dotted_path_support",
"$BUILD_DIR/third_party/s2/s2" ])
env.CppUnitTest("hash_test", [ "hash_test.cpp" ],
diff --git a/src/mongo/db/geo/geoparser.cpp b/src/mongo/db/geo/geoparser.cpp
index 7e58a768aa8..2be29d1dd7a 100644
--- a/src/mongo/db/geo/geoparser.cpp
+++ b/src/mongo/db/geo/geoparser.cpp
@@ -34,6 +34,7 @@
#include <string>
#include <vector>
+#include "mongo/db/bson/dotted_path_support.h"
#include "mongo/db/geo/shapes.h"
#include "mongo/db/jsobj.h"
#include "mongo/util/log.h"
@@ -47,6 +48,8 @@ namespace mongo {
using std::unique_ptr;
using std::stringstream;
+namespace dps = ::mongo::dotted_path_support;
+
// This field must be present, and...
static const string GEOJSON_TYPE = "type";
// Have one of these values:
@@ -525,7 +528,7 @@ Status GeoParser::parseMultiPoint(const BSONObj& obj, MultiPointWithCRS* out) {
return status;
out->points.clear();
- BSONElement coordElt = obj.getFieldDotted(GEOJSON_COORDINATES);
+ BSONElement coordElt = dps::extractElementAtPath(obj, GEOJSON_COORDINATES);
status = parseArrayOfCoordinates(coordElt, &out->points);
if (!status.isOK())
return status;
@@ -546,7 +549,7 @@ Status GeoParser::parseMultiLine(const BSONObj& obj, bool skipValidation, MultiL
if (!status.isOK())
return status;
- BSONElement coordElt = obj.getFieldDotted(GEOJSON_COORDINATES);
+ BSONElement coordElt = dps::extractElementAtPath(obj, GEOJSON_COORDINATES);
if (Array != coordElt.type())
return BAD_VALUE("MultiLineString coordinates must be an array");
@@ -576,7 +579,7 @@ Status GeoParser::parseMultiPolygon(const BSONObj& obj,
if (!status.isOK())
return status;
- BSONElement coordElt = obj.getFieldDotted(GEOJSON_COORDINATES);
+ BSONElement coordElt = dps::extractElementAtPath(obj, GEOJSON_COORDINATES);
if (Array != coordElt.type())
return BAD_VALUE("MultiPolygon coordinates must be an array");
@@ -668,7 +671,7 @@ Status GeoParser::parseCenterSphere(const BSONObj& obj, CapWithCRS* out) {
Status GeoParser::parseGeometryCollection(const BSONObj& obj,
bool skipValidation,
GeometryCollection* out) {
- BSONElement coordElt = obj.getFieldDotted(GEOJSON_GEOMETRIES);
+ BSONElement coordElt = dps::extractElementAtPath(obj, GEOJSON_GEOMETRIES);
if (Array != coordElt.type())
return BAD_VALUE("GeometryCollection geometries must be an array");
@@ -780,7 +783,7 @@ GeoParser::GeoSpecifier GeoParser::parseGeoSpecifier(const BSONElement& type) {
}
GeoParser::GeoJSONType GeoParser::parseGeoJSONType(const BSONObj& obj) {
- BSONElement type = obj.getFieldDotted(GEOJSON_TYPE);
+ BSONElement type = dps::extractElementAtPath(obj, GEOJSON_TYPE);
if (String != type.type()) {
return GeoParser::GEOJSON_UNKNOWN;
}