diff options
author | Kevin Matulef <matulef@gmail.com> | 2012-12-27 03:50:15 -0500 |
---|---|---|
committer | Kevin Matulef <matulef@gmail.com> | 2012-12-27 03:51:48 -0500 |
commit | a02754295ab258f2d10f1c1d668c3f24c633afb1 (patch) | |
tree | e5875f8255a65ac9665fa13091a34cfe31ff45f7 /src/mongo/db/keypattern.cpp | |
parent | db368e2aa0e520e835416c3dde8668da7dd1366f (diff) | |
download | mongo-a02754295ab258f2d10f1c1d668c3f24c633afb1.tar.gz |
SERVER-7668 append MinKey instead of null when extending tag boundary
Diffstat (limited to 'src/mongo/db/keypattern.cpp')
-rw-r--r-- | src/mongo/db/keypattern.cpp | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/src/mongo/db/keypattern.cpp b/src/mongo/db/keypattern.cpp index 96229b70fd8..5123048d816 100644 --- a/src/mongo/db/keypattern.cpp +++ b/src/mongo/db/keypattern.cpp @@ -21,6 +21,8 @@ #include "mongo/db/hasher.h" #include "mongo/db/queryutil.h" +using namespace mongoutils; + namespace mongo { BSONObj KeyPattern::extractSingleKey(const BSONObj& doc ) const { @@ -61,6 +63,41 @@ namespace mongo { return true; } + BSONObj KeyPattern::extendRangeBound( const BSONObj& bound , bool makeUpperInclusive ) const { + BSONObjBuilder newBound( bound.objsize() ); + + BSONObjIterator src( bound ); + BSONObjIterator pat( _pattern ); + + while( src.more() ){ + massert( 16649 , + str::stream() << "keyPattern " << _pattern << " shorter than bound " << bound, + pat.more() ); + BSONElement srcElt = src.next(); + BSONElement patElt = pat.next(); + massert( 16634 , + str::stream() << "field names of bound " << bound + << " do not match those of keyPattern " << _pattern , + str::equals( srcElt.fieldName() , patElt.fieldName() ) ); + newBound.append( srcElt ); + } + while( pat.more() ){ + BSONElement patElt = pat.next(); + // for non 1/-1 field values, like {a : "hashed"}, treat order as ascending + int order = patElt.isNumber() ? patElt.numberInt() : 1; + // flip the order semantics if this is an upper bound + if ( makeUpperInclusive ) order *= -1; + + if( order > 0 ){ + newBound.appendMinKey( patElt.fieldName() ); + } + else { + newBound.appendMaxKey( patElt.fieldName() ); + } + } + return newBound.obj(); + } + typedef vector<pair<BSONObj,BSONObj> >::const_iterator BoundListIter; BoundList KeyPattern::keyBounds( const FieldRangeSet& queryConstraints ) const { |