Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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

  • Loading branch information...
commit 0d656aa0478d18d6a26e5f0cf14b8e3cb6bda8e4 1 parent 5946dbf
authored
3  db/query.cpp
@@ -420,6 +420,9 @@ namespace mongo {
420 420
         if ( query.isEmpty() ){
421 421
             long long num = d->nrecords;
422 422
             num = num - cmd["skip"].numberLong();
  423
+            if ( num < 0 ) {
  424
+                num = 0;
  425
+            }
423 426
             if ( cmd["limit"].isNumber() ){
424 427
                 long long limit = cmd["limit"].numberLong();
425 428
                 if ( limit < num ){
5  jstests/count5.js
@@ -6,7 +6,7 @@ for ( i=0; i<100; i++ ){
6 6
     t.save( { x : i } );
7 7
 }
8 8
 
9  
-q = { x : { $gt : 25 , $lte : 75 } }
  9
+q = { x : { $gt : 25 , $lte : 75 } };
10 10
 
11 11
 assert.eq( 50 , t.find( q ).count() , "A" );
12 12
 assert.eq( 50 , t.find( q ).itcount() , "B" );
@@ -25,3 +25,6 @@ assert.eq( 2 , t.find( q ).skip(48).limit(5).size() , "I" );
25 25
 
26 26
 assert.eq( 20 , t.find().limit(20).size() , "J" );
27 27
 
  28
+assert.eq( 0 , t.find().skip(120).size() , "K" );
  29
+assert.eq( 1 , db.$cmd.findOne( { count: "count5" } )["ok"] , "L" );
  30
+assert.eq( 1 , db.$cmd.findOne( { count: "count5", skip: 120 } )["ok"] , "M" );

0 notes on commit 0d656aa

Please sign in to comment.
Something went wrong with that request. Please try again.