Module: Mingo::Finders

Included in:
Mingo
Defined in:
lib/mingo/finders.rb

Instance Method Summary collapse

Instance Method Details

#find(selector = {}, options = {}, &block) ⇒ Object



11
12
13
14
15
# 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 = {}) ⇒ Object



3
4
5
6
7
8
9
# 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