summaryrefslogtreecommitdiff
path: root/src/mongo/db/index/expression_keys_private.cpp
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/index/expression_keys_private.cpp
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/index/expression_keys_private.cpp')
-rw-r--r--src/mongo/db/index/expression_keys_private.cpp18
1 files changed, 10 insertions, 8 deletions
diff --git a/src/mongo/db/index/expression_keys_private.cpp b/src/mongo/db/index/expression_keys_private.cpp
index 9afc653127f..e44c950758a 100644
--- a/src/mongo/db/index/expression_keys_private.cpp
+++ b/src/mongo/db/index/expression_keys_private.cpp
@@ -32,6 +32,7 @@
#include <utility>
+#include "mongo/db/bson/dotted_path_support.h"
#include "mongo/db/fts/fts_index_format.h"
#include "mongo/db/geo/geoconstants.h"
#include "mongo/db/geo/geometry_container.h"
@@ -51,6 +52,8 @@ namespace {
using namespace mongo;
+namespace dps = ::mongo::dotted_path_support;
+
//
// Helper functions for getHaystackKeys
//
@@ -220,7 +223,7 @@ void ExpressionKeysPrivate::get2DKeys(const BSONObj& obj,
// Get all the nested location fields, but don't return individual elements from
// the last array, if it exists.
- obj.getFieldsDotted(params.geo.c_str(), bSet, false);
+ dps::extractAllElementsAlongPath(obj, params.geo.c_str(), bSet, false);
if (bSet.empty())
return;
@@ -289,7 +292,7 @@ void ExpressionKeysPrivate::get2DKeys(const BSONObj& obj,
++i) {
// Get *all* fields for the index key
BSONElementSet eSet;
- obj.getFieldsDotted(i->first, eSet);
+ dps::extractAllElementsAlongPath(obj, i->first, eSet);
if (eSet.size() == 0)
b.appendNull("");
@@ -329,7 +332,7 @@ void ExpressionKeysPrivate::getHashKeys(const BSONObj& obj,
const CollatorInterface* collator,
BSONObjSet* keys) {
const char* cstr = hashedField.c_str();
- BSONElement fieldVal = obj.getFieldDottedOrArray(cstr);
+ BSONElement fieldVal = dps::extractElementAtPath(obj, cstr);
// Convert strings to comparison keys.
BSONObj fieldValObj;
@@ -365,7 +368,7 @@ void ExpressionKeysPrivate::getHaystackKeys(const BSONObj& obj,
const std::vector<std::string>& otherFields,
double bucketSize,
BSONObjSet* keys) {
- BSONElement loc = obj.getFieldDotted(geoField);
+ BSONElement loc = dps::extractElementAtPath(obj, geoField);
if (loc.eoo()) {
return;
@@ -390,9 +393,8 @@ void ExpressionKeysPrivate::getHaystackKeys(const BSONObj& obj,
BSONElementSet all;
- // This is getFieldsDotted (plural not singular) since the object we're indexing
- // may be an array.
- obj.getFieldsDotted(otherFields[0], all);
+ // The object we're indexing may be an array.
+ dps::extractAllElementsAlongPath(obj, otherFields[0], all);
if (all.size() == 0) {
// We're indexing a document that doesn't have the secondary non-geo field present.
@@ -444,7 +446,7 @@ void ExpressionKeysPrivate::getS2Keys(const BSONObj& obj,
// the value of the field, or they're transformed if the field is geo.
BSONElementSet fieldElements;
// false means Don't expand the last array, duh.
- obj.getFieldsDotted(e.fieldName(), fieldElements, false);
+ dps::extractAllElementsAlongPath(obj, e.fieldName(), fieldElements, false);
BSONObjSet keysForThisField;
if (IndexNames::GEO_2DSPHERE == e.valuestr()) {