'Order by' like Mongoose.js
See original GitHub issueIs 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:
- Created 7 years ago
- Reactions:6
- Comments:6 (4 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
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()
andSequelize.col()
. You would not be able to support that with an object literal.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.