Module: Mongoid::Collections::ClassMethods
- Defined in:
- lib/mongoid/collections.rb
Overview
:nodoc:
Instance Method Summary collapse
-
#collection ⇒ Object
Returns the collection associated with this
Document
. -
#db ⇒ Object
Return the database associated with this collection.
-
#index_information ⇒ Object
Convenience method for getting index information from the collection.
-
#logger=(logger) ⇒ Object
The MongoDB logger is not exposed through the driver to be changed after initialization of the connection, this is a hacky way around that if logging needs to be changed at runtime.
-
#store_in(name) ⇒ Object
Macro for setting the collection name to store in.
Instance Method Details
#collection ⇒ Object
Returns the collection associated with this Document
. If the document is embedded, there will be no collection associated with it.
Returns: Mongo::Collection
20 21 22 23 24 |
# File 'lib/mongoid/collections.rb', line 20 def collection raise Errors::InvalidCollection.new(self) if && !cyclic self._collection || set_collection add_indexes; self._collection end |
#db ⇒ Object
Return the database associated with this collection.
Example:
Person.db
31 32 33 |
# File 'lib/mongoid/collections.rb', line 31 def db collection.db end |
#index_information ⇒ Object
Convenience method for getting index information from the collection.
Example:
Person.index_information
40 41 42 |
# File 'lib/mongoid/collections.rb', line 40 def index_information collection.index_information end |
#logger=(logger) ⇒ Object
The MongoDB logger is not exposed through the driver to be changed after initialization of the connection, this is a hacky way around that if logging needs to be changed at runtime.
Example:
Person.logger = Logger.new($stdout)
51 52 53 |
# File 'lib/mongoid/collections.rb', line 51 def logger=(logger) db.connection.instance_variable_set(:@logger, logger) end |
#store_in(name) ⇒ Object
Macro for setting the collection name to store in.
Example:
Person.store_in :population
60 61 62 63 |
# File 'lib/mongoid/collections.rb', line 60 def store_in(name) self.collection_name = name.to_s set_collection end |