Permalink
Browse files

skipping all results shouldn't be an error for count operations

  • Loading branch information...
1 parent 5946dbf commit 0d656aa0478d18d6a26e5f0cf14b8e3cb6bda8e4 Mike Dirolf committed Nov 14, 2009
Showing with 7 additions and 1 deletion.
  1. +3 −0 db/query.cpp
  2. +4 −1 jstests/count5.js
View
@@ -420,6 +420,9 @@ namespace mongo {
if ( query.isEmpty() ){
long long num = d->nrecords;
num = num - cmd["skip"].numberLong();
+ if ( num < 0 ) {
+ num = 0;
+ }
if ( cmd["limit"].isNumber() ){
long long limit = cmd["limit"].numberLong();
if ( limit < num ){
View
@@ -6,7 +6,7 @@ for ( i=0; i<100; i++ ){
t.save( { x : i } );
}
-q = { x : { $gt : 25 , $lte : 75 } }
+q = { x : { $gt : 25 , $lte : 75 } };
assert.eq( 50 , t.find( q ).count() , "A" );
assert.eq( 50 , t.find( q ).itcount() , "B" );
@@ -25,3 +25,6 @@ assert.eq( 2 , t.find( q ).skip(48).limit(5).size() , "I" );
assert.eq( 20 , t.find().limit(20).size() , "J" );
+assert.eq( 0 , t.find().skip(120).size() , "K" );
+assert.eq( 1 , db.$cmd.findOne( { count: "count5" } )["ok"] , "L" );
+assert.eq( 1 , db.$cmd.findOne( { count: "count5", skip: 120 } )["ok"] , "M" );

0 comments on commit 0d656aa

Please sign in to comment.