Method: MongoDoc::Contexts::Mongo#max

Defined in:
lib/mongodoc/contexts/mongo.rb

#max(field) ⇒ Object

Return the max value for a field.

This will take the internally built selector and options and pass them on to the Ruby driver’s group() method on the collection. The collection itself will be retrieved from the class provided, and once the query has returned it will provided a grouping of keys with sums.

Example:

context.max(:age)

Returns:

A numeric max value.



143
144
145
# File 'lib/mongodoc/contexts/mongo.rb', line 143

def max(field)
  grouped(:max, field.to_s, MAX_REDUCE)
end