module Mongoid::Sessions::Options::ClassMethods

Public Instance Methods

with(options) click to toggle source

Tell the next persistance operation to store in a specific collection, database or session.

@example Create a document in a different collection.

Model.with(collection: "secondary").create(name: "test")

@example Create a document in a different database.

Model.with(database: "secondary").create(name: "test")

@example Create a document in a different session.

Model.with(session: "secondary").create(name: "test")

@example Create with a combination of options.

Model.with(session: "sharded", database: "secondary").create

@param [ Hash ] options The storage options.

@option options [ String, Symbol ] :collection The collection name. @option options [ String, Symbol ] :database The database name. @option options [ String, Symbol ] :session The session name.

@return [ Class ] The model class.

@since 3.0.0

# File lib/mongoid/sessions/options.rb, line 101
def with(options)
  Proxy.new(self, (persistence_options || {}).merge(options))
end