summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorKyle Suarez <kyle.suarez@mongodb.com>2017-06-27 12:00:57 -0400
committerKyle Suarez <kyle.suarez@mongodb.com>2017-06-27 12:01:18 -0400
commit18bc61d22123da5897d275eb92576522a1bab4de (patch)
tree39f43c8b7302656645bc52844cea55f282c1d689 /src
parent17d4ddebffb53b85656fa6d370af137691cc1458 (diff)
downloadmongo-18bc61d22123da5897d275eb92576522a1bab4de.tar.gz
SERVER-29618 fix serialization of geo match expressions
Diffstat (limited to 'src')
-rw-r--r--src/mongo/db/matcher/expression_geo.cpp14
-rw-r--r--src/mongo/db/matcher/expression_geo.h10
-rw-r--r--src/mongo/db/matcher/expression_parser_geo.cpp14
3 files changed, 17 insertions, 21 deletions
diff --git a/src/mongo/db/matcher/expression_geo.cpp b/src/mongo/db/matcher/expression_geo.cpp
index 7129c6413e0..104eefec513 100644
--- a/src/mongo/db/matcher/expression_geo.cpp
+++ b/src/mongo/db/matcher/expression_geo.cpp
@@ -364,7 +364,11 @@ bool GeoMatchExpression::matchesSingleElement(const BSONElement& e) const {
void GeoMatchExpression::debugString(StringBuilder& debug, int level) const {
_debugAddSpace(debug, level);
- debug << "GEO raw = " << _rawObj.toString();
+
+ BSONObjBuilder builder;
+ serialize(&builder);
+ debug << "GEO raw = " << builder.obj().toString();
+
MatchExpression::TagData* td = getTag();
if (NULL != td) {
debug << " ";
@@ -374,7 +378,9 @@ void GeoMatchExpression::debugString(StringBuilder& debug, int level) const {
}
void GeoMatchExpression::serialize(BSONObjBuilder* out) const {
- out->appendElements(_rawObj);
+ BSONObjBuilder subobj(out->subobjStart(path()));
+ subobj.appendElements(_rawObj);
+ subobj.doneFast();
}
bool GeoMatchExpression::equivalent(const MatchExpression* other) const {
@@ -431,7 +437,9 @@ void GeoNearMatchExpression::debugString(StringBuilder& debug, int level) const
}
void GeoNearMatchExpression::serialize(BSONObjBuilder* out) const {
- out->appendElements(_rawObj);
+ BSONObjBuilder subobj(out->subobjStart(path()));
+ subobj.appendElements(_rawObj);
+ subobj.doneFast();
}
bool GeoNearMatchExpression::equivalent(const MatchExpression* other) const {
diff --git a/src/mongo/db/matcher/expression_geo.h b/src/mongo/db/matcher/expression_geo.h
index 856b31045f8..60ae66f3cb6 100644
--- a/src/mongo/db/matcher/expression_geo.h
+++ b/src/mongo/db/matcher/expression_geo.h
@@ -108,12 +108,11 @@ public:
const GeoExpression& getGeoExpression() const {
return *_query;
}
- const BSONObj getRawObj() const {
- return _rawObj;
- }
private:
+ // The original geo specification provided by the user.
BSONObj _rawObj;
+
// Share ownership of our query with all of our clones
std::shared_ptr<const GeoExpression> _query;
bool _canSkipValidation;
@@ -183,12 +182,11 @@ public:
const GeoNearExpression& getData() const {
return *_query;
}
- const BSONObj getRawObj() const {
- return _rawObj;
- }
private:
+ // The original geo specification provided by the user.
BSONObj _rawObj;
+
// Share ownership of our query with all of our clones
std::shared_ptr<const GeoNearExpression> _query;
};
diff --git a/src/mongo/db/matcher/expression_parser_geo.cpp b/src/mongo/db/matcher/expression_parser_geo.cpp
index d706ef65193..433af63ed3d 100644
--- a/src/mongo/db/matcher/expression_parser_geo.cpp
+++ b/src/mongo/db/matcher/expression_parser_geo.cpp
@@ -53,12 +53,7 @@ StatusWithMatchExpression expressionParserGeoCallbackReal(const char* name,
unique_ptr<GeoMatchExpression> e = make_unique<GeoMatchExpression>();
- // Until the index layer accepts non-BSON predicates, or special indices are moved into
- // stages, we have to clean up the raw object so it can be passed down to the index
- // layer.
- BSONObjBuilder bob;
- bob.append(name, section);
- Status s = e->init(name, gq.release(), bob.obj());
+ Status s = e->init(name, gq.release(), section);
if (!s.isOK())
return StatusWithMatchExpression(s);
return {std::move(e)};
@@ -70,12 +65,7 @@ StatusWithMatchExpression expressionParserGeoCallbackReal(const char* name,
return StatusWithMatchExpression(s);
}
unique_ptr<GeoNearMatchExpression> e = make_unique<GeoNearMatchExpression>();
- // Until the index layer accepts non-BSON predicates, or special indices are moved into
- // stages, we have to clean up the raw object so it can be passed down to the index
- // layer.
- BSONObjBuilder bob;
- bob.append(name, section);
- s = e->init(name, nq.release(), bob.obj());
+ s = e->init(name, nq.release(), section);
if (!s.isOK())
return StatusWithMatchExpression(s);
return {std::move(e)};