Skip to content

Commit

Permalink
SERVER-2829 doc
Browse files Browse the repository at this point in the history
  • Loading branch information
astaple committed Mar 25, 2011
1 parent 819f400 commit 273dda0
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
4 changes: 3 additions & 1 deletion db/matcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) {
Expand All @@ -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 );
}
Expand Down
7 changes: 6 additions & 1 deletion db/matcher.h
Original file line number Diff line number Diff line change
Expand Up @@ -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; }

Expand Down
2 changes: 2 additions & 0 deletions jstests/in8.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]} ) );
Expand Down

0 comments on commit 273dda0

Please sign in to comment.