Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

fix exists with index SERVER-708

  • Loading branch information...
commit da4507b7c6fb088f55a368d404e15ce349ada692 1 parent 02d6682
Eliot authored March 06, 2010
13  db/matcher.cpp
@@ -139,8 +139,10 @@ namespace mongo {
139 139
     {
140 140
         _needRecord = ! ( 
141 141
                          _docMatcher.keyMatch() && 
142  
-                         _keyMatcher.jsobj.nFields() == _docMatcher.jsobj.nFields()
  142
+                         _keyMatcher.jsobj.nFields() == _docMatcher.jsobj.nFields() &&
  143
+                         ! _keyMatcher.hasType( BSONObj::opEXISTS )
143 144
                           );
  145
+
144 146
     }
145 147
     
146 148
     bool CoveredIndexMatcher::matches(const BSONObj &key, const DiskLoc &recLoc , MatchDetails * details ) {
@@ -148,7 +150,7 @@ namespace mongo {
148 150
             details->reset();
149 151
         
150 152
         if ( _keyMatcher.keyMatch() ) {
151  
-            if ( !_keyMatcher.matches(key) ) {
  153
+            if ( !_keyMatcher.matches(key, details ) ){
152 154
                 return false;
153 155
             }
154 156
         }
@@ -710,6 +712,13 @@ namespace mongo {
710 712
         return true;
711 713
     }
712 714
 
  715
+    bool Matcher::hasType( BSONObj::MatchType type ) const {
  716
+        for ( unsigned i=0; i<basics.size() ; i++ )
  717
+            if ( basics[i].compareOp == type )
  718
+                return true;
  719
+        return false;
  720
+    }
  721
+
713 722
     struct JSObj1 js1;
714 723
 
715 724
 #pragma pack(1)
1  db/matcher.h
@@ -140,6 +140,7 @@ namespace mongo {
140 140
 
141 141
         bool atomic() const { return _atomic; }
142 142
 
  143
+        bool hasType( BSONObj::MatchType type ) const;
143 144
     private:
144 145
         void addBasic(const BSONElement &e, int c, bool isNot) {
145 146
             // TODO May want to selectively ignore these element types based on op type.
14  jstests/exists2.js
... ...
@@ -0,0 +1,14 @@
  1
+
  2
+t = db.exists2;
  3
+t.drop();
  4
+
  5
+t.save( { a : 1 , b : 1 } )
  6
+t.save( { a : 1 , b : 1 , c : 1 } )
  7
+
  8
+assert.eq( 2 , t.find().itcount() , "A1" );
  9
+assert.eq( 2 , t.find( { a : 1 , b : 1 } ).itcount() , "A2" );
  10
+assert.eq( 1 , t.find( { a : 1 , b : 1 , c : { "$exists" : true } } ).itcount() , "A3" );
  11
+
  12
+t.ensureIndex( { a : 1 , b : 1 , c : 1 } )
  13
+assert.eq( 1 , t.find( { a : 1 , b : 1 , c : { "$exists" : true } } ).itcount() , "B1" );
  14
+

0 notes on commit da4507b

Please sign in to comment.
Something went wrong with that request. Please try again.