diff options
author | Eliot Horowitz <eliot@10gen.com> | 2010-03-06 17:53:50 -0500 |
---|---|---|
committer | Eliot Horowitz <eliot@10gen.com> | 2010-03-06 17:53:50 -0500 |
commit | da4507b7c6fb088f55a368d404e15ce349ada692 (patch) | |
tree | d8b38767ce7fe9949da838bc76b430c04a661381 | |
parent | 02d6682a839602371e3cf1f9e91da03946fbe996 (diff) | |
download | mongo-da4507b7c6fb088f55a368d404e15ce349ada692.tar.gz |
fix exists with index SERVER-708
-rw-r--r-- | db/matcher.cpp | 13 | ||||
-rw-r--r-- | db/matcher.h | 1 | ||||
-rw-r--r-- | jstests/exists2.js | 14 |
3 files changed, 26 insertions, 2 deletions
diff --git a/db/matcher.cpp b/db/matcher.cpp index e5eb3f3cb75..91fff7fcea1 100644 --- a/db/matcher.cpp +++ b/db/matcher.cpp @@ -139,8 +139,10 @@ namespace mongo { { _needRecord = ! ( _docMatcher.keyMatch() && - _keyMatcher.jsobj.nFields() == _docMatcher.jsobj.nFields() + _keyMatcher.jsobj.nFields() == _docMatcher.jsobj.nFields() && + ! _keyMatcher.hasType( BSONObj::opEXISTS ) ); + } bool CoveredIndexMatcher::matches(const BSONObj &key, const DiskLoc &recLoc , MatchDetails * details ) { @@ -148,7 +150,7 @@ namespace mongo { details->reset(); if ( _keyMatcher.keyMatch() ) { - if ( !_keyMatcher.matches(key) ) { + if ( !_keyMatcher.matches(key, details ) ){ return false; } } @@ -710,6 +712,13 @@ namespace mongo { return true; } + bool Matcher::hasType( BSONObj::MatchType type ) const { + for ( unsigned i=0; i<basics.size() ; i++ ) + if ( basics[i].compareOp == type ) + return true; + return false; + } + struct JSObj1 js1; #pragma pack(1) diff --git a/db/matcher.h b/db/matcher.h index da68cf4f358..72d6ec59c33 100644 --- a/db/matcher.h +++ b/db/matcher.h @@ -140,6 +140,7 @@ namespace mongo { bool atomic() const { return _atomic; } + bool hasType( BSONObj::MatchType type ) const; private: void addBasic(const BSONElement &e, int c, bool isNot) { // TODO May want to selectively ignore these element types based on op type. diff --git a/jstests/exists2.js b/jstests/exists2.js new file mode 100644 index 00000000000..a9b4d1ed7b3 --- /dev/null +++ b/jstests/exists2.js @@ -0,0 +1,14 @@ + +t = db.exists2; +t.drop(); + +t.save( { a : 1 , b : 1 } ) +t.save( { a : 1 , b : 1 , c : 1 } ) + +assert.eq( 2 , t.find().itcount() , "A1" ); +assert.eq( 2 , t.find( { a : 1 , b : 1 } ).itcount() , "A2" ); +assert.eq( 1 , t.find( { a : 1 , b : 1 , c : { "$exists" : true } } ).itcount() , "A3" ); + +t.ensureIndex( { a : 1 , b : 1 , c : 1 } ) +assert.eq( 1 , t.find( { a : 1 , b : 1 , c : { "$exists" : true } } ).itcount() , "B1" ); + |