Module: MongoDoc::Finders

Defined in:
lib/mongodoc/finders.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.extended(base) ⇒ Object



5
6
7
# File 'lib/mongodoc/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 Mongo::ObjectID)

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



24
25
26
# File 'lib/mongodoc/finders.rb', line 24

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

#find_allObject

Find all Documents in the collections

Person.find_all



31
32
33
# File 'lib/mongodoc/finders.rb', line 31

def find_all
  criteria
end

#find_one(conditions_or_id) ⇒ Object

Find a Document based on id (String or Mongo::ObjectID) or conditions

Person.find_one('1') Person.find_one(:where => {:age.gt > 25})



40
41
42
43
44
45
46
# File 'lib/mongodoc/finders.rb', line 40

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