diff --git a/lib/page.js b/lib/page.js index 903315b..d48c527 100644 --- a/lib/page.js +++ b/lib/page.js @@ -21,7 +21,7 @@ module.exports = function(mongoose) { options.start = (options && options.start ? options.start : defaults.start); options.count = (options && options.count ? options.count : defaults.count); - if (maxDocs > 0 && options.count > maxDocs) { + if (maxDocs > 0 && (options.count > maxDocs || options.count === 0)) { options.count = maxDocs; } diff --git a/package.json b/package.json index 0d8106c..370c9be 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name" : "mongoose-middleware", "description" : "Middleware for mongoose that makes filtering, sorting, pagination and projection chainable and simple to apply", - "version" : "0.2.1", + "version" : "0.2.2", "scripts" : { "pretest" : "rm -rf lib-cov ; jshint lib/*.js ; jscoverage lib lib-cov", "test" : "mocha --check-leaks -R spec -r ./test/common.js -u bdd ./test/lib/*.js", diff --git a/test/lib/page.js b/test/lib/page.js index 736aee8..c14e23c 100644 --- a/test/lib/page.js +++ b/test/lib/page.js @@ -67,6 +67,26 @@ describe('page', function () { }); }); + it('should default limit to maxDocs when 0 is supplied as count', function (done) { + pageLib.initialize({ maxDocs: 25 }); + + var options = { + start : 0, + count : 0 + }; + + Kitteh + .find() + .page(options, function (err, data) { + should.not.exist(err); + data.should.not.be.empty; + limit.should.equals(25); + skip.should.equals(0); + + done(); + }); + }); + it('should properly return error when one occurs during count', function (done) { countError = new Error('icanhazacounterr');