Query.prototype.sort()

Parameters
  • arg «Object|String»
Returns:
  • «Query» this

Sets the sort order

If an object is passed, values allowed are asc, desc, ascending, descending, 1, and -1.

If a string is passed, it must be a space delimited list of path names. The sort order of each path is ascending unless the path name is prefixed with - which will be treated as descending.

Example

  1. // sort by "field" ascending and "test" descending
  2. query.sort({ field: 'asc', test: -1 });
  3. // equivalent
  4. query.sort('field -test');

Note

Cannot be used with distinct()