Module: Mongo::Model::QueryMixin::ClassMethods
- Includes:
- DynamicFinders
- Defined in:
- lib/mongo/model/query_mixin.rb
Instance Method Summary collapse
- #all(selector = {}, options = {}, &block) ⇒ Object
- #count(selector = {}, options = {}) ⇒ Object
- #each(selector = {}, options = {}, &block) ⇒ Object
- #exists?(selector = {}, options = {}) ⇒ Boolean (also: #exist?)
- #first(selector = {}, options = {}) ⇒ Object
- #first!(selector = {}, options = {}) ⇒ Object
- #query(*args) ⇒ Object
Instance Method Details
#all(selector = {}, options = {}, &block) ⇒ Object
17 18 19 20 21 22 23 24 25 |
# File 'lib/mongo/model/query_mixin.rb', line 17 def all selector = {}, = {}, &block if block each selector, , &block else list = [] each(selector, ){|doc| list << doc} list end end |
#count(selector = {}, options = {}) ⇒ Object
5 6 7 |
# File 'lib/mongo/model/query_mixin.rb', line 5 def count selector = {}, = {} collection.count selector, end |
#each(selector = {}, options = {}, &block) ⇒ Object
13 14 15 |
# File 'lib/mongo/model/query_mixin.rb', line 13 def each selector = {}, = {}, &block collection.each selector, , &block end |
#exists?(selector = {}, options = {}) ⇒ Boolean Also known as: exist?
31 32 33 |
# File 'lib/mongo/model/query_mixin.rb', line 31 def exists? selector = {}, = {} count(selector, ) > 0 end |
#first(selector = {}, options = {}) ⇒ Object
9 10 11 |
# File 'lib/mongo/model/query_mixin.rb', line 9 def first selector = {}, = {} collection.first selector, end |
#first!(selector = {}, options = {}) ⇒ Object
27 28 29 |
# File 'lib/mongo/model/query_mixin.rb', line 27 def first! selector = {}, = {} first(selector, ) || raise(Mongo::NotFound, "document with selector #{selector} not found!") end |