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(:where => {:age.gt > 25})



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

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