Method: Mongoid::Contexts::Mongo#execute

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

#execute(paginating = false) ⇒ Object

Execute the context. This will take the selector and options and pass them on to the Ruby driver’s find() method on the collection. The collection itself will be retrieved from the class provided, and once the query has returned new documents of the type of class provided will be instantiated.

Example:

context.execute

Returns:

An enumerable Cursor.



92
93
94
95
96
97
98
99
100
# File 'lib/mongoid/contexts/mongo.rb', line 92

def execute(paginating = false)
  cursor = klass.collection.find(selector, process_options)
  if cursor
    @count = cursor.count if paginating
    cursor
  else
    []
  end
end