Skip to content

Commit 952120a

Browse files
committed
fix(query): handle toConstructor() with entries-style sort syntax
Fix #8159
1 parent 1e0cc7a commit 952120a

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

lib/query.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,15 @@ Query.prototype.toConstructor = function toConstructor() {
188188

189189
p.options = {};
190190

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

193201
p.op = this.op;
194202
p._conditions = utils.clone(this._conditions);

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
"mongodb": "3.3.2",
2626
"mongoose-legacy-pluralize": "1.0.2",
2727
"mpath": "0.6.0",
28-
"mquery": "3.2.1",
28+
"mquery": "3.2.2",
2929
"ms": "2.1.2",
3030
"regexp-clone": "1.0.0",
3131
"safe-buffer": "5.1.2",

0 commit comments

Comments
 (0)