Module: Mongoid::Collections::ClassMethods

Defined in:
lib/mongoid/collections.rb

Overview

:nodoc:

Instance Method Summary collapse

Instance Method Details

#collectionCollection

Returns the collection associated with this Document. If the document is embedded, there will be no collection associated with it unless it’s in a cyclic relation.

Examples:

Get the collection.

Model.collection

Returns:

  • (Collection)

    The Mongoid collection wrapper.

Raises:



54
55
56
57
58
# File 'lib/mongoid/collections.rb', line 54

def collection
  raise Errors::InvalidCollection.new(self) if embedded? && !cyclic
  self._collection || set_collection
  add_indexes; self._collection
end

#dbMongo::DB

Return the database associated with this collection.

Examples:

Get the database object.

Model.db

Returns:

  • (Mongo::DB)

    The Mongo daatabase object.



66
67
68
# File 'lib/mongoid/collections.rb', line 66

def db
  collection.db
end

#index_informationArray

Convenience method for getting index information from the collection.

Examples:

Get the index information from the collection.

Model.index_information

Returns:

  • (Array)

    The collection index information.



76
77
78
# File 'lib/mongoid/collections.rb', line 76

def index_information
  collection.index_information
end

#store_in(name, options = {}) ⇒ Object

Macro for setting the collection name to store in.

Examples:

Store in a separate collection than the default.

Model.store_in :population

Store in a capped collection.

Model.store_in :population, :capped => true, :max => 10000

Parameters:

  • name (Symbol)

    The name of the collection.

  • options (Hash) (defaults to: {})

    The collection options.

Options Hash (options):

  • :capped (true, false)

    If the collection is capped.

  • :size (Integer)

    The capped collection size.

  • :max (Integer)

    The maximum number of docs in the capped collection.



95
96
97
98
# File 'lib/mongoid/collections.rb', line 95

def store_in(name, options = {})
  self.collection_name = name.to_s
  set_collection(options)
end