Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

fix count w / $all issue SERVER-382 SERVER-320

  • Loading branch information...
commit 860a94f85281d73b50e056993881367491f7cabf 1 parent c66c479
@erh erh authored
Showing with 32 additions and 9 deletions.
  1. +3 −4 db/query.cpp
  2. +12 −5 jstests/all2.js
  3. +17 −0 jstests/count4.js
View
7 db/query.cpp
@@ -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();
View
17 jstests/all2.js
@@ -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" );
@@ -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" );
+
View
17 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" );
Please sign in to comment.
Something went wrong with that request. Please try again.