module Mingo::Finders

Public Instance Methods

find(selector = {}, options = {}, &block) click to toggle source
# File lib/mingo/finders.rb, line 11
def find(selector = {}, options = {}, &block)
  selector = {:_id => {'$in' => selector}} if Array === selector
  options = { :transformer => lambda {|doc| self.new(doc)} }.update(options)
  collection.find(selector, options, &block)
end
first(id_or_selector = nil, options = {}) click to toggle source
# File lib/mingo/finders.rb, line 3
def first(id_or_selector = nil, options = {})
  unless id_or_selector.nil? or Hash === id_or_selector
    id_or_selector = BSON::ObjectId[id_or_selector]
  end
  options = { :transformer => lambda {|doc| self.new(doc)} }.update(options)
  collection.find_one(id_or_selector, options)
end