Skip to content

Commit

Permalink
found issue where when 0 is passed as count, mongo interprets this as…
Browse files Browse the repository at this point in the history
… no limit
  • Loading branch information
brozeph committed Jun 17, 2013
1 parent 4892cac commit ffb39c5
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/page.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
20 changes: 20 additions & 0 deletions test/lib/page.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand Down

0 comments on commit ffb39c5

Please sign in to comment.