question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

'Order by' like Mongoose.js

See original GitHub issue

Is possible use the order like Mongoose.js?

  • Current way:
something.findOne({
  order: [
    ['username', 'DESC'],
    ['firstname', 'ASC'],
    ['lastname', 'DESC'],
  ]
})
  • Like Mongoose.js:
something.findOne({
  order: { username : -1, firstname : 1, lastname : -1 }
})

What do you think? 👯

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:6
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
felixfbeckercommented, Aug 10, 2016

But it is not guaranteed and non-standard. There are lint rules that require that all object literals have alphabetically sorted properties. Coworkers might move around keys because they don’t expect it to change anything. There is no way to change the order at runtime. Minifiers might mangle them during their code -> AST -> minified code conversion.

Plus the current syntax also supports Sequelize.literal() and Sequelize.col(). You would not be able to support that with an object literal.

1reaction
felixfbeckercommented, Aug 9, 2016

Imo the current syntax is much more concise and there is no reason why it should be changed. Also your example does not specify in what order the attributes should be considered.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to sort in mongoose? - Stack Overflow
This is how I got sort to work in mongoose.js 2.0.4 var query = EmailModel.find({domain:"gmail.com"}); query.sort('priority', 1); query.exec(function(error, ...
Read more >
Sorting with mongoose and mongoDB - Working with Data
I have a userModel that has about 5 fields that I would like to be sorted in Ascending or Descending when I find({})...
Read more >
Mongoose v6.8.2: Query
Returns a wrapper around a mongodb driver cursor. A QueryCursor exposes a Streams3 interface, as well as a .next() function. The .cursor() function...
Read more >
In Mongoose, how sort by date and other field (node.js)
Sorting in Mongoose has evolved over the releases such that some of these answers are no longer valid. As of the 4.1.x release...
Read more >
`find()` with LIKE in Mongoose - Mastering JS
MongoDB does not have a LIKE operator akin to SQL, but MongoDB does support queries by regular expressions. Here's how you can use...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found