summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJason Rassi <rassi@10gen.com>2013-12-12 23:15:28 -0500
committerJason Rassi <rassi@10gen.com>2013-12-13 14:01:30 -0500
commitf5bc2c78e4e14785e0a39970d4163ebb062d05f9 (patch)
tree09d194ab70eb9996423740271e97e0f66dadccca
parent1d034bab093f4f7d3b264c50e78207b94a0e267e (diff)
downloadmongo-f5bc2c78e4e14785e0a39970d4163ebb062d05f9.tar.gz
SERVER-10026 Refer to $meta values by string constants
-rw-r--r--src/mongo/db/commands/geonear.cpp4
-rw-r--r--src/mongo/db/exec/projection_exec.cpp11
-rw-r--r--src/mongo/db/fts/fts_command_mongod.cpp2
-rw-r--r--src/mongo/db/query/lite_parsed_query.cpp16
-rw-r--r--src/mongo/db/query/lite_parsed_query.h11
-rw-r--r--src/mongo/db/query/parsed_projection.cpp18
6 files changed, 39 insertions, 23 deletions
diff --git a/src/mongo/db/commands/geonear.cpp b/src/mongo/db/commands/geonear.cpp
index 44a445a6b4a..22c4c222c95 100644
--- a/src/mongo/db/commands/geonear.cpp
+++ b/src/mongo/db/commands/geonear.cpp
@@ -164,8 +164,8 @@ namespace mongo {
uassert(17297, "distanceMultiplier must be non-negative", distanceMultiplier >= 0);
}
- BSONObj projObj = BSON("$pt" << BSON("$meta" << "geoNearPoint") <<
- "$dis" << BSON("$meta" << "geoNearDistance"));
+ BSONObj projObj = BSON("$pt" << BSON("$meta" << LiteParsedQuery::metaGeoNearPoint) <<
+ "$dis" << BSON("$meta" << LiteParsedQuery::metaGeoNearDistance));
CanonicalQuery* cq;
if (!CanonicalQuery::canonicalize(ns, rewritten, BSONObj(), projObj, 0, numWanted, BSONObj(), &cq).isOK()) {
diff --git a/src/mongo/db/exec/projection_exec.cpp b/src/mongo/db/exec/projection_exec.cpp
index 7964cd6dd14..d78c2d59a7f 100644
--- a/src/mongo/db/exec/projection_exec.cpp
+++ b/src/mongo/db/exec/projection_exec.cpp
@@ -31,6 +31,7 @@
#include "mongo/db/exec/working_set_computed_data.h"
#include "mongo/db/matcher/expression_parser.h"
#include "mongo/db/matcher/expression.h"
+#include "mongo/db/query/lite_parsed_query.h"
#include "mongo/util/mongoutils/str.h"
namespace mongo {
@@ -121,19 +122,19 @@ namespace mongo {
}
else if (mongoutils::str::equals(e2.fieldName(), "$meta")) {
verify(String == e2.type());
- if (mongoutils::str::equals(e2.valuestr(), "textScore")) {
+ if (e2.valuestr() == LiteParsedQuery::metaTextScore) {
_meta[e.fieldName()] = META_TEXT_SCORE;
}
- else if (mongoutils::str::equals(e2.valuestr(), "diskloc")) {
+ else if (e2.valuestr() == LiteParsedQuery::metaDiskLoc) {
_meta[e.fieldName()] = META_DISKLOC;
}
- else if (mongoutils::str::equals(e2.valuestr(), "geoNearPoint")) {
+ else if (e2.valuestr() == LiteParsedQuery::metaGeoNearPoint) {
_meta[e.fieldName()] = META_GEONEAR_POINT;
}
- else if (mongoutils::str::equals(e2.valuestr(), "geoNearDistance")) {
+ else if (e2.valuestr() == LiteParsedQuery::metaGeoNearDistance) {
_meta[e.fieldName()] = META_GEONEAR_DIST;
}
- else if (mongoutils::str::equals(e2.valuestr(), "indexKey")) {
+ else if (e2.valuestr() == LiteParsedQuery::metaIndexKey) {
_hasReturnKey = true;
// The index key clobbers everything so just stop parsing here.
return;
diff --git a/src/mongo/db/fts/fts_command_mongod.cpp b/src/mongo/db/fts/fts_command_mongod.cpp
index 8ea994fe4a5..89d943eaf80 100644
--- a/src/mongo/db/fts/fts_command_mongod.cpp
+++ b/src/mongo/db/fts/fts_command_mongod.cpp
@@ -85,7 +85,7 @@ namespace mongo {
BSONObj queryObj = queryBob.obj();
// We sort by the score.
- BSONObj sortSpec = BSON("$s" << BSON("$meta" << "textScore"));
+ BSONObj sortSpec = BSON("$s" << BSON("$meta" << LiteParsedQuery::metaTextScore));
// We also project the score into the document and strip it out later during the reformatting
// of the results.
diff --git a/src/mongo/db/query/lite_parsed_query.cpp b/src/mongo/db/query/lite_parsed_query.cpp
index 1996dd4a189..28ee8086fdf 100644
--- a/src/mongo/db/query/lite_parsed_query.cpp
+++ b/src/mongo/db/query/lite_parsed_query.cpp
@@ -26,6 +26,12 @@ namespace mongo {
const string LiteParsedQuery::cmdOptionMaxTimeMS("maxTimeMS");
const string LiteParsedQuery::queryOptionMaxTimeMS("$maxTimeMS");
+ const string LiteParsedQuery::metaTextScore("textScore");
+ const string LiteParsedQuery::metaGeoNearDistance("geoNearDistance");
+ const string LiteParsedQuery::metaGeoNearPoint("geoNearPoint");
+ const string LiteParsedQuery::metaDiskLoc("diskloc");
+ const string LiteParsedQuery::metaIndexKey("indexKey");
+
// static
Status LiteParsedQuery::make(const QueryMessage& qm, LiteParsedQuery** out) {
auto_ptr<LiteParsedQuery> pq(new LiteParsedQuery());
@@ -108,7 +114,7 @@ namespace mongo {
if (mongo::String != metaElt.type()) {
return false;
}
- if (!mongoutils::str::equals("textScore", metaElt.valuestr())) {
+ if (LiteParsedQuery::metaTextScore != metaElt.valuestr()) {
return false;
}
// must have exactly 1 element
@@ -137,7 +143,7 @@ namespace mongo {
if (mongo::String != metaElt.type()) {
return false;
}
- if (!mongoutils::str::equals("diskloc", metaElt.valuestr())) {
+ if (LiteParsedQuery::metaDiskLoc != metaElt.valuestr()) {
return false;
}
// must have exactly 1 element
@@ -324,7 +330,8 @@ namespace mongo {
BSONObjBuilder projBob;
projBob.appendElements(_proj);
// XXX: what's the syntax here?
- BSONObj indexKey = BSON("$$" << BSON("$meta" << "indexKey"));
+ BSONObj indexKey = BSON("$$" <<
+ BSON("$meta" << LiteParsedQuery::metaIndexKey));
projBob.append(indexKey.firstElement());
_proj = projBob.obj();
}
@@ -338,7 +345,8 @@ namespace mongo {
if (e.trueValue()) {
BSONObjBuilder projBob;
projBob.appendElements(_proj);
- BSONObj metaDiskLoc = BSON("$diskLoc" << BSON("$meta" << "diskloc"));
+ BSONObj metaDiskLoc = BSON("$diskLoc" <<
+ BSON("$meta" << LiteParsedQuery::metaDiskLoc));
projBob.append(metaDiskLoc.firstElement());
_proj = projBob.obj();
}
diff --git a/src/mongo/db/query/lite_parsed_query.h b/src/mongo/db/query/lite_parsed_query.h
index deab008849e..b6a05b2c3ff 100644
--- a/src/mongo/db/query/lite_parsed_query.h
+++ b/src/mongo/db/query/lite_parsed_query.h
@@ -94,12 +94,17 @@ namespace mongo {
*/
static BSONObj normalizeSortOrder(const BSONObj& sortObj);
- // Name of the maxTimeMS command option.
+ // Names of the maxTimeMS command and query option.
static const string cmdOptionMaxTimeMS;
-
- // Name of the maxTimeMS query option.
static const string queryOptionMaxTimeMS;
+ // Names of the $meta projection values.
+ static const string metaTextScore;
+ static const string metaGeoNearDistance;
+ static const string metaGeoNearPoint;
+ static const string metaDiskLoc;
+ static const string metaIndexKey;
+
const string& ns() const { return _ns; }
bool isLocalDB() const { return _ns.compare(0, 6, "local.") == 0; }
diff --git a/src/mongo/db/query/parsed_projection.cpp b/src/mongo/db/query/parsed_projection.cpp
index 02e232343b2..85ae36a1c15 100644
--- a/src/mongo/db/query/parsed_projection.cpp
+++ b/src/mongo/db/query/parsed_projection.cpp
@@ -28,6 +28,8 @@
#include "mongo/db/query/parsed_projection.h"
+#include "mongo/db/query/lite_parsed_query.h"
+
namespace mongo {
/**
@@ -143,23 +145,23 @@ namespace mongo {
return Status(ErrorCodes::BadValue, "unexpected argument to $meta in proj");
}
- if (!mongoutils::str::equals(e2.valuestr(), "textScore")
- && !mongoutils::str::equals(e2.valuestr(), "diskloc")
- && !mongoutils::str::equals(e2.valuestr(), "indexKey")
- && !mongoutils::str::equals(e2.valuestr(), "geoNearDistance")
- && !mongoutils::str::equals(e2.valuestr(), "geoNearPoint")) {
+ if (e2.valuestr() != LiteParsedQuery::metaTextScore
+ && e2.valuestr() != LiteParsedQuery::metaDiskLoc
+ && e2.valuestr() != LiteParsedQuery::metaIndexKey
+ && e2.valuestr() != LiteParsedQuery::metaGeoNearDistance
+ && e2.valuestr() != LiteParsedQuery::metaGeoNearPoint) {
return Status(ErrorCodes::BadValue,
"unsupported $meta operator: " + e2.str());
}
// This clobbers everything else.
- if (mongoutils::str::equals(e2.valuestr(), "indexKey")) {
+ if (e2.valuestr() == LiteParsedQuery::metaIndexKey) {
hasIndexKeyProjection = true;
}
- else if (mongoutils::str::equals(e2.valuestr(), "geoNearDistance")) {
+ else if (e2.valuestr() == LiteParsedQuery::metaGeoNearDistance) {
wantGeoNearDistance = true;
}
- else if (mongoutils::str::equals(e2.valuestr(), "geoNearPoint")) {
+ else if (e2.valuestr() == LiteParsedQuery::metaGeoNearPoint) {
wantGeoNearPoint = true;
}
}