Skip to content

Commit

Permalink
fix(query): handle toConstructor() with entries-style sort syntax
Browse files Browse the repository at this point in the history
Fix #8159
  • Loading branch information
vkarpov15 committed Sep 22, 2019
1 parent 1e0cc7a commit 952120a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
10 changes: 9 additions & 1 deletion lib/query.js
Expand Up @@ -188,7 +188,15 @@ Query.prototype.toConstructor = function toConstructor() {

p.options = {};

p.setOptions(this.options);
// Need to handle `sort()` separately because entries-style `sort()` syntax
// `sort([['prop1', 1]])` confuses mquery into losing the outer nested array.
// See gh-8159
const options = Object.assign({}, this.options);
if (options.sort != null) {
p.sort(options.sort);
delete options.sort;
}
p.setOptions(options);

p.op = this.op;
p._conditions = utils.clone(this._conditions);
Expand Down
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -25,7 +25,7 @@
"mongodb": "3.3.2",
"mongoose-legacy-pluralize": "1.0.2",
"mpath": "0.6.0",
"mquery": "3.2.1",
"mquery": "3.2.2",
"ms": "2.1.2",
"regexp-clone": "1.0.0",
"safe-buffer": "5.1.2",
Expand Down

0 comments on commit 952120a

Please sign in to comment.