From f93a8c3c93eb03e65198b340f3ac551af8f6baac Mon Sep 17 00:00:00 2001 From: Dobes Vandermeer Date: Wed, 5 Sep 2018 09:26:51 -0700 Subject: [PATCH] fix(cursor): allow `$meta` based sort when passing an array to `sort()` You may pass an object with a `$meta` key in place of the order parameter to `sort`. The previous code would incorrectly reject this input as illegal. See https://docs.mongodb.com/manual/reference/method/cursor.sort/#sort-metadata for documentation. --- lib/cursor.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/cursor.js b/lib/cursor.js index 69293213ec..4a0b815f67 100644 --- a/lib/cursor.js +++ b/lib/cursor.js @@ -557,7 +557,7 @@ Cursor.prototype.sort = function(keyOrList, direction) { value[1] = 1; } else if (x[1] === 'desc') { value[1] = -1; - } else if (x[1] === 1 || x[1] === -1) { + } else if (x[1] === 1 || x[1] === -1 || x[1].$meta) { value[1] = x[1]; } else { throw new MongoError(