Skip to content

Commit

Permalink
fix count w / $all issue SERVER-382 SERVER-320
Browse files Browse the repository at this point in the history
  • Loading branch information
erh committed Oct 23, 2009
1 parent c66c479 commit 860a94f
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 9 deletions.
7 changes: 3 additions & 4 deletions db/query.cpp
Expand Up @@ -347,15 +347,14 @@ namespace mongo {
virtual void init() {
query_ = spec_.getObjectField( "query" );
c_ = qp().newCursor();
if ( qp().exactKeyMatch() ) {
matcher_.reset( new KeyValJSMatcher( query_, c_->indexKeyPattern() ) );
if ( qp().exactKeyMatch() && ! matcher_->needRecord() ) {
query_ = qp().simplifiedQuery( qp().indexKey() );
bc_ = dynamic_cast< BtreeCursor* >( c_.get() );
bc_->forgetEndKey();
}
else {
matcher_.reset( new KeyValJSMatcher( query_, c_->indexKeyPattern() ) );
}
}

virtual void next() {
if ( !c_->ok() ) {
setComplete();
Expand Down
17 changes: 12 additions & 5 deletions jstests/all2.js
Expand Up @@ -48,11 +48,6 @@ t.save( { a : [ 3 , 4 ] } )

state = "more no index";

function check( n , q , e ){
assert.eq( n , t.find( q ).count() , tojson( q ) + " " + e + " count " + state );
assert.eq( n , t.find( q ).itcount() , tojson( q ) + " " + e + " itcount" + state );
}

check( 1 , { "a" : { $in : [ 1 ] } } , "A" );
check( 2 , { "a" : { $in : [ 2 ] } } , "B" );

Expand All @@ -77,3 +72,15 @@ check( 3 , { "a" : { $in : [ 1 , 3 ] } } , "E" );
check( 1 , { "a" : { $all : [ 1 , 2 ] } } , "F" );
check( 1 , { "a" : { $all : [ 2 , 3 ] } } , "G" );
check( 0 , { "a" : { $all : [ 1 , 3 ] } } , "H" );


// more 2

state = "more 2"

t.drop();
t.save( { name : [ "harry","jack","tom" ] } )
check( 0 , { name : { $all : ["harry","john"] } } , "A" );
t.ensureIndex( { name : 1 } );
check( 0 , { name : { $all : ["harry","john"] } } , "B" );

17 changes: 17 additions & 0 deletions jstests/count4.js
@@ -0,0 +1,17 @@

t = db.count4;
t.drop();

for ( i=0; i<100; i++ ){
t.save( { x : i } );
}

q = { x : { $gt : 25 , $lte : 75 } }

assert.eq( 50 , t.find( q ).count() , "A" );
assert.eq( 50 , t.find( q ).itcount() , "B" );

t.ensureIndex( { x : 1 } );

assert.eq( 50 , t.find( q ).count() , "C" );
assert.eq( 50 , t.find( q ).itcount() , "D" );

0 comments on commit 860a94f

Please sign in to comment.