Module: Mongoid::Clients::ClassMethods

Extended by:
Gem::Deprecate
Defined in:
lib/mongoid/clients.rb

Instance Method Summary collapse

Instance Method Details

#collectionMongo::Collection

Get the collection for this model from the client. Will check for an overridden collection name from the store_in macro or the collection with a pluralized model name.

Examples:

Get the model’s collection.

Model.collection

Returns:

  • (Mongo::Collection)

    The collection.

Since:

  • 3.0.0



137
138
139
# File 'lib/mongoid/clients.rb', line 137

def collection
  mongo_client[collection_name]
end

#mongo_clientMongo::Client Also known as: mongo_session

Get the client for this model. This is determined in the following order:

1. Any custom configuration provided by the 'store_in' macro.
2. The 'default' client as provided in the mongoid.yml

Examples:

Get the client.

Model.mongo_client

Returns:

  • (Mongo::Client)

    The default mongo client.

Since:

  • 3.0.0



117
118
119
120
121
122
123
# File 'lib/mongoid/clients.rb', line 117

def mongo_client
  name = client_name
  client = Clients.with_name(name)
  client = client.use(database_name)
  client = client.with(self.persistence_options)
  Clients.set(name, client)
end