mirror of
https://github.com/mongodb/mongo.git
synced 2024-11-30 17:10:48 +01:00
SERVER-653 fix problem where some special query types would only work if they were the first element
This commit is contained in:
parent
3284b51028
commit
079031215d
@ -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 );
|
||||
|
@ -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" );
|
@ -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" );
|
@ -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() );
|
@ -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 );
|
||||
|
||||
|
@ -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" );
|
Loading…
Reference in New Issue
Block a user