Permalink
Browse files

SERVER-1883 expand nested array fields when testing document for matc…

…h with previous or clause
  • Loading branch information...
1 parent d3b2ddd commit 41b422b789dd8ce8c9ae57063bc6fcca29182912 @astaple astaple committed Oct 3, 2010
Showing with 16 additions and 18 deletions.
  1. +9 −16 db/queryutil.cpp
  2. +7 −2 jstests/or8.js
View
@@ -1029,23 +1029,16 @@ namespace mongo {
BSONElement kk = k.next();
int number = (int) kk.number();
bool forward = ( number >= 0 ? 1 : -1 ) * ( _direction >= 0 ? 1 : -1 ) > 0;
- BSONElement e = obj.getFieldDotted( kk.fieldName() );
- if ( e.eoo() ) {
- e = staticNull.firstElement();
- }
- if ( e.type() == Array ) {
- BSONObjIterator j( e.embeddedObject() );
- bool match = false;
- while( j.more() ) {
- if ( matchesElement( j.next(), i, forward ) ) {
- match = true;
- break;
- }
- }
- if ( !match ) {
- return false;
+ BSONElementSet keys;
+ obj.getFieldsDotted( kk.fieldName(), keys );
+ bool match = false;
+ for( BSONElementSet::const_iterator j = keys.begin(); j != keys.end(); ++j ) {
+ if ( matchesElement( *j, i, forward ) ) {
+ match = true;
+ break;
}
- } else if ( !matchesElement( e, i, forward ) ) {
+ }
+ if ( !match ) {
return false;
}
}
View
@@ -19,5 +19,10 @@ assert.eq.automsg( "2", "t.find({ $or: [ {a:1}, {a:3}, { a: {$in:[]} } ] } ).toA
t.drop();
t.save( {a:{b:1,c:1}} );
-t.ensureIndex( { 'a.b':1, 'a.c':1 } );
-assert.eq( 1, t.find( {$or: [ { 'a.b':1 }, { 'a.c':1 } ] } ).itcount() );
+t.ensureIndex( { 'a.b':1 } );
+t.ensureIndex( { 'a.c':1 } );
+assert.eq( 1, t.find( {$or: [ { 'a.b':1 }, { 'a.c':1 } ] } ).itcount() );
+
+t.remove();
+t.save( {a:[{b:1,c:1},{b:2,c:1}]} );
+assert.eq( 1, t.find( {$or: [ { 'a.b':2 }, { 'a.c':1 } ] } ).itcount() );

0 comments on commit 41b422b

Please sign in to comment.