Module: Mingo::Finders
- Included in:
- Mingo
- Defined in:
- lib/mingo/finders.rb
Instance Method Summary collapse
- #find(selector = {}, options = {}, &block) ⇒ Object
- #first(id_or_selector = nil, options = {}) ⇒ Object
Instance Method Details
#find(selector = {}, options = {}, &block) ⇒ Object
11 12 13 14 15 |
# File 'lib/mingo/finders.rb', line 11 def find(selector = {}, = {}, &block) selector = {:_id => {'$in' => selector}} if Array === selector = { :transformer => lambda {|doc| self.new(doc)} }.update() collection.find(selector, , &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, = {}) unless id_or_selector.nil? or Hash === id_or_selector id_or_selector = BSON::ObjectId[id_or_selector] end = { :transformer => lambda {|doc| self.new(doc)} }.update() collection.find_one(id_or_selector, ) end |