Module: MongoDoc::Finders

Defined in:
lib/mongo_doc/finders.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.extended(base) ⇒ Object



5
6
7
# File 'lib/mongo_doc/finders.rb', line 5

def self.extended(base)
  base.extend(Criteria) unless base === Criteria
end

Instance Method Details

#find(*args) ⇒ Object

Find a Document based on id (String or BSON::ObjectId)

Person.find('1') Person.find(obj_id_1, obj_id_2)



13
14
15
# File 'lib/mongo_doc/finders.rb', line 13

def find(*args)
  criteria.id(*args)
end

#find_allObject

Find all Documents in the collections

Person.find_all



20
21
22
# File 'lib/mongo_doc/finders.rb', line 20

def find_all
  criteria
end

#find_one(conditions_or_id) ⇒ Object

Find a Document based on id (String or BSON::ObjectId) or conditions

Person.find_one('1') Person.find_one(:conditions => {:age.gt => 25}, :order_by => [[:name, :asc]])



30
31
32
33
34
35
36
37
# File 'lib/mongo_doc/finders.rb', line 30

def find_one(conditions_or_id)
  return nil if conditions_or_id.nil?
  if Hash === conditions_or_id
    Mongoid::Criteria.translate(self, conditions_or_id).one
  else
    Mongoid::Criteria.translate(self, conditions_or_id)
  end
end