Skip to content

Commit

Permalink
Automatticgh-2374 make sort usable with count op
Browse files Browse the repository at this point in the history
  • Loading branch information
alabid committed Oct 30, 2014
1 parent 944a0a8 commit 9af249f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lib/query.js
Expand Up @@ -1332,6 +1332,11 @@ Query.prototype.sort = function (arg) {
nArg = arg;
}

// workaround for gh-2374 when sort is called after count
// if previous operation is count, we ignore
if (this.op == 'count') {
delete this.op;
}
return Query.base.sort.call(this, nArg);
}

Expand Down
9 changes: 9 additions & 0 deletions test/query.test.js
Expand Up @@ -1492,5 +1492,14 @@ describe('Query', function(){
done();
});
});

it('ignores count when passed to sort', function(done) {
var db = start();
var Product = db.model('Product', 'Product_setOptions_test');
Product.find().count({}).sort({ _id: 1 }).exec(function(error) {
assert.ifError(error);
done();
});
});
});
})

0 comments on commit 9af249f

Please sign in to comment.