Error "Invalid sort() argument. Must be a string, object, or array"

Open
#139 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
30/100
Issue type
Bug
Clarity
Needs clarification
Activity status
Stale
Tech stack
coffeescript, javascript, mongodb, nodejs
Domain
databases

Research direction

No file or test is named in the payload. Start by reproducing the intermittent failure with the shown findOne({}, null, { sort: { age: -1 } }) call, then locate where mquery validates the sort option and raises Invalid sort() argument. Done means a minimal reproduction, the rejecting code path identified, and a test covering the object-sort case.

Written by the indexing model from the issue text.

Description

I have my source code below using coffeescript:
`personSchema = new mongoose.Schema({
name: String,
age: Number
})

Person = mongoose.model('Person', personSchema)

options = {
  sort: { age: -1 }
}

Person.findOne({}, null, options, (err, result) ->
  if err
    console.error('err:', err)
  else
    console.log('result:', result)
)`

Even though the sort value I am using is in the correct syntax for sort query. But every now and then I get the above error. Do you know the reason why?
Version coffee-script: 1.7.1
mongoose: 4.10.6
mquery: 2.3.3
mongodb: 2.2.34

Dominant language
JavaScript
Stars
485
Forks
68
PR merge metrics
No merged PRs in 30d

Getting set up

  • No Dockerfile or Docker Compose file
  • Has a pull request template
  • No contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from mongoosejs/mquery

All issues in mongoosejs/mquery

Similar issues

More JavaScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.