summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAaron <aaron@10gen.com>2010-10-03 14:29:49 -0700
committerAaron <aaron@10gen.com>2010-10-11 23:49:23 -0700
commit13d28aae02cab41679bf09074fefd2b28bbe30c8 (patch)
tree400e54caa33ef0e7d2dde0490522027745147020
parent6f0c76a552e60f2768796f61e55088dfda66784d (diff)
downloadmongo-13d28aae02cab41679bf09074fefd2b28bbe30c8.tar.gz
SERVER-1883 expand nested array fields when testing document for match with previous or clause
-rw-r--r--db/queryutil.cpp25
-rw-r--r--jstests/or8.js9
2 files changed, 16 insertions, 18 deletions
diff --git a/db/queryutil.cpp b/db/queryutil.cpp
index ad083e5d739..21530460b17 100644
--- a/db/queryutil.cpp
+++ b/db/queryutil.cpp
@@ -982,23 +982,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;
}
}
diff --git a/jstests/or8.js b/jstests/or8.js
index 3cf9d26de5b..d08f22718c1 100644
--- a/jstests/or8.js
+++ b/jstests/or8.js
@@ -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() ); \ No newline at end of file
+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() );