From 273dda0b61a10084798dc59d455ea735d19074bc Mon Sep 17 00:00:00 2001 From: Aaron Date: Fri, 25 Mar 2011 11:04:49 -0700 Subject: [PATCH] SERVER-2829 doc --- db/matcher.cpp | 4 +++- db/matcher.h | 7 ++++++- jstests/in8.js | 2 ++ 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/db/matcher.cpp b/db/matcher.cpp index aa61705a5a91a..5674f29a64f60 100644 --- a/db/matcher.cpp +++ b/db/matcher.cpp @@ -419,7 +419,7 @@ namespace mongo { Matcher::Matcher( const Matcher &other, const BSONObj &key ) : where(0), constrainIndexKey_( key ), haveSize(), all(), hasArray(0), haveNeg(), _atomic(false), nRegex(0) { - // do not include fields which would make keyMatch() false + // do not include field matches which would make keyMatch() false for( vector< ElementMatcher >::const_iterator i = other.basics.begin(); i != other.basics.end(); ++i ) { if ( key.hasField( i->toMatch.fieldName() ) ) { switch( i->compareOp ) { @@ -436,12 +436,14 @@ namespace mongo { break; } } + // Can't match an array to its first indexed element. if ( !i->isNot && !inContainsArray ) { basics.push_back( *i ); } break; } default: { + // Can't match an array to its first indexed element. if ( !i->isNot && i->toMatch.type() != Array ) { basics.push_back( *i ); } diff --git a/db/matcher.h b/db/matcher.h index d242df64452dc..36591656ffefe 100644 --- a/db/matcher.h +++ b/db/matcher.h @@ -143,7 +143,12 @@ namespace mongo { // fast rough check to see if we must load the real doc - we also // compare field counts against covereed index matcher; for $or clauses // we just compare field counts - bool keyMatch() const { return !all && !haveSize && !hasArray && !haveNeg; } + bool keyMatch() const { return + !all + && !haveSize + && !hasArray // We can't match an array to its first indexed element using keymatch + && !haveNeg; + } bool atomic() const { return _atomic; } diff --git a/jstests/in8.js b/jstests/in8.js index dd56e0e5efb99..0620c0917ef82 100644 --- a/jstests/in8.js +++ b/jstests/in8.js @@ -10,6 +10,8 @@ t.save( {key: [[2]]} ); function doTest() { assert.eq( 1, t.count( {key:[1]} ) ); assert.eq( 1, t.count( {key:{$in:[[1]]}} ) ); + assert.eq( 1, t.count( {key:{$in:[[1]],$ne:[2]}} ) ); + assert.eq( 1, t.count( {key:{$in:[[1]],$type:1}} ) ); assert.eq( 1, t.count( {key:['1']} ) ); assert.eq( 1, t.count( {key:{$in:[['1']]}} ) ); assert.eq( 1, t.count( {key:[2]} ) );