summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTess Avitabile <tess.avitabile@mongodb.com>2016-02-02 12:26:31 -0500
committerTess Avitabile <tess.avitabile@mongodb.com>2016-02-03 10:25:51 -0500
commit407457dc34ea5afc3b983096c80959815b888632 (patch)
treeacb52c17fcaf8a06155cf77fffd83ae6a20f2ae0
parent7ee4cc1c5b946d9855fef217f8293216e954fd53 (diff)
downloadmongo-407457dc34ea5afc3b983096c80959815b888632.tar.gz
SERVER-8564 Clean up CanonicalQuery::isValid()
-rw-r--r--src/mongo/db/query/canonical_query.cpp24
1 files changed, 9 insertions, 15 deletions
diff --git a/src/mongo/db/query/canonical_query.cpp b/src/mongo/db/query/canonical_query.cpp
index a48b846c044..ddddc3fa932 100644
--- a/src/mongo/db/query/canonical_query.cpp
+++ b/src/mongo/db/query/canonical_query.cpp
@@ -519,15 +519,17 @@ Status CanonicalQuery::isValid(MatchExpression* root, const LiteParsedQuery& par
}
// NEAR cannot have a $natural sort or $natural hint.
+ const BSONObj& sortObj = parsed.getSort();
+ BSONElement sortNaturalElt = sortObj["$natural"];
+ const BSONObj& hintObj = parsed.getHint();
+ BSONElement hintNaturalElt = hintObj["$natural"];
if (numGeoNear > 0) {
- BSONObj sortObj = parsed.getSort();
- if (!sortObj["$natural"].eoo()) {
+ if (sortNaturalElt) {
return Status(ErrorCodes::BadValue,
"geoNear expression not allowed with $natural sort order");
}
- BSONObj hintObj = parsed.getHint();
- if (!hintObj["$natural"].eoo()) {
+ if (hintNaturalElt) {
return Status(ErrorCodes::BadValue,
"geoNear expression not allowed with $natural hint");
}
@@ -539,20 +541,12 @@ Status CanonicalQuery::isValid(MatchExpression* root, const LiteParsedQuery& par
}
// TEXT and {$natural: ...} sort order cannot both be in the query.
- if (numText > 0) {
- const BSONObj& sortObj = parsed.getSort();
- BSONObjIterator it(sortObj);
- while (it.more()) {
- BSONElement elt = it.next();
- if (str::equals("$natural", elt.fieldName())) {
- return Status(ErrorCodes::BadValue,
- "text expression not allowed with $natural sort order");
- }
- }
+ if (numText > 0 && sortNaturalElt) {
+ return Status(ErrorCodes::BadValue, "text expression not allowed with $natural sort order");
}
// TEXT and hint cannot both be in the query.
- if (numText > 0 && !parsed.getHint().isEmpty()) {
+ if (numText > 0 && !hintObj.isEmpty()) {
return Status(ErrorCodes::BadValue, "text and hint not allowed in same query");
}