Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"sort cannot be used with count" in 3.9.3 #2374

Closed
mshekera opened this issue Oct 13, 2014 · 1 comment
Closed

"sort cannot be used with count" in 3.9.3 #2374

mshekera opened this issue Oct 13, 2014 · 1 comment
Milestone

Comments

@mshekera
Copy link

Almost the same problem as in #1950, but now sort crashes with "sort cannot be used with count" after count.

For example, this code (coffescript) works:

mongoQuery = this.findAll(query, null, options, fields);
mongoQuery.sort(_id: -1);

async.parallel({
    count: function (next) {
        mongoQuery.count(next);
    },
    data: function (next) {
        mongoQuery
            .limit(limit)
            .skip((page - 1) * limit)
            .exec(next);
    }
}, cb)

But this one (sort moved to data function in async.parallel and seems like called after count) - don't:

mongoQuery = this.findAll(query, null, options, fields);

async.parallel({
    count: function (next) {
        mongoQuery.count(next);
    },
    data: function (next) {
        mongoQuery
            .sort(_id: -1)
            .limit(limit)
            .skip((page - 1) * limit)
            .exec(next);
    }
}, cb)

As I mentioned, I think there are the same problem as in issue #1950, because Query.prototype.sort still using mquery and wasn't rewrote like Query.prototype.count in this commit.

Head of stack trace:

Error: sort cannot be used with count
  at Query._validate (/path/to/project/node_modules/mongoose/node_modules/mquery/lib/mquery.js:2422:11)
  at Query.sort (/path/to/project/node_modules/mongoose/node_modules/mquery/lib/mquery.js:1175:8)
  at Query.sort (/path/to/project/node_modules/mongoose/lib/query.js:1335:26)
  at Object.async.parallel.data (/path/to/project/some/file.coffee:28:7)
@vkarpov15
Copy link
Collaborator

Thanks for pointing this out, I'll fix it.

@vkarpov15 vkarpov15 added this to the 3.9.5 milestone Oct 17, 2014
alabid added a commit to alabid/mongoose that referenced this issue Oct 30, 2014
vkarpov15 added a commit that referenced this issue Oct 30, 2014
gh-2374 make sort usable with count op
vkarpov15 added a commit that referenced this issue Mar 6, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants