Module: Mongo::Model::Query::ClassMethods
Instance Method Summary
collapse
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
in the class Mongo::DynamicFinders
Instance Method Details
#all(selector = {}, opts = {}, &block) ⇒ Object
17
18
19
20
21
22
23
24
25
|
# File 'lib/mongo_db/model/query.rb', line 17
def all selector = {}, opts = {}, &block
if block
each selector, opts, &block
else
list = []
each(selector, opts){|doc| list << doc}
list
end
end
|
#count(selector = {}, opts = {}) ⇒ Object
5
6
7
|
# File 'lib/mongo_db/model/query.rb', line 5
def count selector = {}, opts = {}
collection.count selector, opts
end
|
#each(selector = {}, opts = {}, &block) ⇒ Object
13
14
15
|
# File 'lib/mongo_db/model/query.rb', line 13
def each selector = {}, opts = {}, &block
collection.each selector, opts, &block
end
|
#exists?(selector = {}, opts = {}) ⇒ Boolean
Also known as:
exist?
31
32
33
|
# File 'lib/mongo_db/model/query.rb', line 31
def exists? selector = {}, opts = {}
count(selector, opts) > 0
end
|
#first(selector = {}, opts = {}) ⇒ Object
9
10
11
|
# File 'lib/mongo_db/model/query.rb', line 9
def first selector = {}, opts = {}
collection.first selector, opts
end
|
#first!(selector = {}, opts = {}) ⇒ Object
27
28
29
|
# File 'lib/mongo_db/model/query.rb', line 27
def first! selector = {}, opts = {}
first(selector, opts) || raise(Mongo::NotFound, "document with selector #{selector} not found!")
end
|