Skip to content

Commit f93a8c3

Browse files
dobesvmbroadst
authored andcommitted
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.
1 parent bd80fb2 commit f93a8c3

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

lib/cursor.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -557,7 +557,7 @@ Cursor.prototype.sort = function(keyOrList, direction) {
557557
value[1] = 1;
558558
} else if (x[1] === 'desc') {
559559
value[1] = -1;
560-
} else if (x[1] === 1 || x[1] === -1) {
560+
} else if (x[1] === 1 || x[1] === -1 || x[1].$meta) {
561561
value[1] = x[1];
562562
} else {
563563
throw new MongoError(

0 commit comments

Comments
 (0)