Method: MongoDoc::Contexts::Mongo#last

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

#lastObject

Return the last result for the Context. Essentially does a find_one on the collection with the sorting reversed. If no sorting parameters have been provided it will default to ids.

Example:

context.last

Returns:

The last document in the collection.



163
164
165
166
167
# File 'lib/mongo_doc/contexts/mongo.rb', line 163

def last
  sorting = options[:sort] || [[:_id, :asc]]
  options[:sort] = sorting.collect { |option| [ option[0], option[1].invert ] }
  collection.find_one(selector, find_options)
end