Method: Mongo::Collection::View::Readable#sort

Defined in:
lib/mongo/collection/view/readable.rb

#sort(spec = nil) ⇒ Hash, View

The key and direction pairs by which the result set will be sorted.

Examples:

Set the sort criteria

view.sort(name: -1)

Parameters:

  • spec (Hash) (defaults to: nil)

    The attributes and directions to sort by.

Returns:

  • (Hash, View)

    Either the sort setting or a new View.

Since:

  • 2.0.0



595
596
597
# File 'lib/mongo/collection/view/readable.rb', line 595

def sort(spec = nil)
  configure(:sort, spec)
end