Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

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 astaple authored
View
16 db/matcher.cpp
@@ -68,17 +68,17 @@ namespace mongo {
ElementMatcher::ElementMatcher( BSONElement _e , int _op ) : toMatch( _e ) , compareOp( _op ) {
if ( _op == BSONObj::opMOD ){
- BSONObj o = _e.embeddedObject().firstElement().embeddedObject();
+ BSONObj o = _e.embeddedObject();
mod = o["0"].numberInt();
modm = o["1"].numberInt();
uassert( 10073 , "mod can't be 0" , mod );
}
else if ( _op == BSONObj::opTYPE ){
- type = (BSONType)(_e.embeddedObject().firstElement().numberInt());
+ type = (BSONType)(_e.numberInt());
}
else if ( _op == BSONObj::opELEM_MATCH ){
- BSONElement m = toMatch.embeddedObjectUserCheck().firstElement();
+ BSONElement m = _e;
uassert( 12517 , "$elemMatch needs an Object" , m.type() == Object );
subMatcher.reset( new Matcher( m.embeddedObject() ) );
}
@@ -263,10 +263,14 @@ namespace mongo {
break;
case BSONObj::opMOD:
case BSONObj::opTYPE:
- case BSONObj::opELEM_MATCH:
+ case BSONObj::opELEM_MATCH: {
+ shared_ptr< BSONObjBuilder > b( new BSONObjBuilder() );
+ _builders.push_back( b );
+ b->appendAs(fe, e.fieldName());
// these are types where ElementMatcher has all the info
- basics.push_back( ElementMatcher( e , op ) );
- break;
+ basics.push_back( ElementMatcher( b->done().firstElement() , op ) );
+ break;
+ }
case BSONObj::opSIZE:{
shared_ptr< BSONObjBuilder > b( new BSONObjBuilder() );
_builders.push_back( b );
View
1  jstests/arrayfind1.js
@@ -36,3 +36,4 @@ res = t.find( { "a" : { $elemMatch : { x : { $gt : 2 } } } } ).explain()
assert( res.cursor.indexOf( "BtreeC" ) == 0 , "C1" );
assert.eq( 2 , t.find( { a : { $elemMatch : { x : { $gt : 2 } } } } ).count() , "D2" );
+assert.eq( 2 , t.find( { a : { $ne:2, $elemMatch : { x : { $gt : 2 } } } } ).count() , "D2" );
View
1  jstests/in.js
@@ -17,3 +17,4 @@ assert.eq( 2 , t.find( { a : { $in : [ 1 , 2 ] } } ).itcount() , "F" );
assert.eq( 0 , t.find( { a : { $in : [] } } ).itcount() , "G" );
+assert.eq( 1 , t.find( { a : { $gt: 1, $in : [ 2 ] } } ).itcount() , "E" );
View
1  jstests/mod1.js
@@ -22,3 +22,4 @@ assert.eq( 1 , t.find( "this.a % 10 == 0" ).itcount() , "B3" );
assert.eq( 1 , t.find( { a : { $mod : [ 10 , 0 ] } } ).itcount() , "B4" );
assert.eq( 4 , t.find( { a : { $mod : [ 10 , 1 ] } } ).explain().nscanned , "B5" );
+assert.eq( 1, t.find( { a: { $gt: 5, $mod : [ 10, 1 ] } } ).itcount() );
View
1  jstests/nin.js
@@ -29,6 +29,7 @@ doTest = function( n ) {
assert.eq( 4, t.find( { a: { $nin: [ 9 ] } } ).count() , n + " G" );
assert.eq( 4, t.find( { a: { $nin: [ 3 ] } } ).count() , n + " H" );
assert.eq( 3, t.find( { a: { $nin: [ 2, 3 ] } } ).count() , n + " I" );
+ assert.eq( 1, t.find( { a: { $ne: 8, $nin: [ 2, 3 ] } } ).count() , n + " I2" );
checkEqual( n + " A" , "a" , 5 );
View
1  jstests/type1.js
@@ -21,3 +21,4 @@ assert.eq( 1 , t.find( { x : { $type : 1 } } ).count() , "B2" );
assert.eq( 3 , t.find( { x : { $type : 2 } } ).count() , "B3" );
assert.eq( 0 , t.find( { x : { $type : 3 } } ).count() , "B4" );
assert.eq( 1 , t.find( { x : { $type : 1 } } ).explain().nscanned , "B5" );
+assert.eq( 1 , t.find( { x : { $regex:"f", $type : 2 } } ).count() , "B3" );
Please sign in to comment.
Something went wrong with that request. Please try again.