diff --git a/lib/query.js b/lib/query.js index b0961a2f97c..714ceb38c54 100644 --- a/lib/query.js +++ b/lib/query.js @@ -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); diff --git a/package.json b/package.json index a363e9ab393..8c25adcdf03 100644 --- a/package.json +++ b/package.json @@ -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",