Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

SERVER-653 fix problem where some special query types would only work…

… if they were the first element
  • Loading branch information...
commit 079031215d946eb118f6228a36eb04dc53b9dac4 1 parent 3284b51
astaple authored February 22, 2010
16  db/matcher.cpp
@@ -68,17 +68,17 @@ namespace mongo {
68 68
 
69 69
     ElementMatcher::ElementMatcher( BSONElement _e , int _op ) : toMatch( _e ) , compareOp( _op ) {
70 70
         if ( _op == BSONObj::opMOD ){
71  
-            BSONObj o = _e.embeddedObject().firstElement().embeddedObject();
  71
+            BSONObj o = _e.embeddedObject();
72 72
             mod = o["0"].numberInt();
73 73
             modm = o["1"].numberInt();
74 74
             
75 75
             uassert( 10073 ,  "mod can't be 0" , mod );
76 76
         }
77 77
         else if ( _op == BSONObj::opTYPE ){
78  
-            type = (BSONType)(_e.embeddedObject().firstElement().numberInt());
  78
+            type = (BSONType)(_e.numberInt());
79 79
         }
80 80
         else if ( _op == BSONObj::opELEM_MATCH ){
81  
-            BSONElement m = toMatch.embeddedObjectUserCheck().firstElement();
  81
+            BSONElement m = _e;
82 82
             uassert( 12517 , "$elemMatch needs an Object" , m.type() == Object );
83 83
             subMatcher.reset( new Matcher( m.embeddedObject() ) );
84 84
         }
@@ -263,10 +263,14 @@ namespace mongo {
263 263
                             break;
264 264
                         case BSONObj::opMOD:
265 265
                         case BSONObj::opTYPE:
266  
-                        case BSONObj::opELEM_MATCH:
  266
+                        case BSONObj::opELEM_MATCH: {
  267
+                            shared_ptr< BSONObjBuilder > b( new BSONObjBuilder() );
  268
+                            _builders.push_back( b );
  269
+                            b->appendAs(fe, e.fieldName());                                
267 270
                             // these are types where ElementMatcher has all the info
268  
-                            basics.push_back( ElementMatcher( e , op ) );
269  
-                            break;
  271
+                            basics.push_back( ElementMatcher( b->done().firstElement() , op ) );
  272
+                            break;                                
  273
+                        }
270 274
                         case BSONObj::opSIZE:{
271 275
                             shared_ptr< BSONObjBuilder > b( new BSONObjBuilder() );
272 276
                             _builders.push_back( b );
1  jstests/arrayfind1.js
@@ -36,3 +36,4 @@ res = t.find( { "a" : { $elemMatch : { x : { $gt : 2 } } } } ).explain()
36 36
 assert( res.cursor.indexOf( "BtreeC" ) == 0 , "C1" );
37 37
 assert.eq( 2 , t.find( { a : { $elemMatch : { x : { $gt : 2 } } } } ).count() , "D2" );
38 38
 
  39
+assert.eq( 2 , t.find( { a : { $ne:2, $elemMatch : { x : { $gt : 2 } } } } ).count() , "D2" );
1  jstests/in.js
@@ -17,3 +17,4 @@ assert.eq( 2 , t.find( { a : { $in : [ 1 , 2 ] } } ).itcount() , "F" );
17 17
 
18 18
 assert.eq( 0 , t.find( { a : { $in : [] } } ).itcount() , "G" );
19 19
 
  20
+assert.eq( 1 , t.find( { a : { $gt: 1, $in : [ 2 ] } } ).itcount() , "E" );
1  jstests/mod1.js
@@ -22,3 +22,4 @@ assert.eq( 1 , t.find( "this.a % 10 == 0" ).itcount() , "B3" );
22 22
 assert.eq( 1 , t.find( { a : { $mod : [ 10 , 0 ] } } ).itcount() , "B4" );
23 23
 assert.eq( 4 , t.find( { a : { $mod : [ 10 , 1 ] } } ).explain().nscanned , "B5" );
24 24
 
  25
+assert.eq( 1, t.find( { a: { $gt: 5, $mod : [ 10, 1 ] } } ).itcount() );
1  jstests/nin.js
@@ -29,6 +29,7 @@ doTest = function( n ) {
29 29
     assert.eq( 4, t.find( { a: { $nin: [ 9 ] } } ).count() , n + " G" );
30 30
     assert.eq( 4, t.find( { a: { $nin: [ 3 ] } } ).count() , n + " H" );
31 31
     assert.eq( 3, t.find( { a: { $nin: [ 2, 3 ] } } ).count() , n + " I" );
  32
+    assert.eq( 1, t.find( { a: { $ne: 8, $nin: [ 2, 3 ] } } ).count() , n + " I2" );
32 33
     
33 34
     checkEqual( n + " A" , "a" , 5 );
34 35
 
1  jstests/type1.js
@@ -21,3 +21,4 @@ assert.eq( 1 , t.find( { x : { $type : 1 } } ).count() , "B2" );
21 21
 assert.eq( 3 , t.find( { x : { $type : 2 } } ).count() , "B3" );
22 22
 assert.eq( 0 , t.find( { x : { $type : 3 } } ).count() , "B4" );
23 23
 assert.eq( 1 , t.find( { x : { $type : 1 } } ).explain().nscanned , "B5" );
  24
+assert.eq( 1 , t.find( { x : { $regex:"f", $type : 2 } } ).count() , "B3" );

0 notes on commit 0790312

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