Module: Mongoid

Extended by:
Mongoid, Loggable, UnitOfWork
Included in:
Mongoid
Defined in:
lib/mongoid.rb,
lib/mongoid/json.rb,
lib/mongoid/dirty.rb,
lib/mongoid/state.rb,
lib/mongoid/atomic.rb,
lib/mongoid/config.rb,
lib/mongoid/fields.rb,
lib/mongoid/factory.rb,
lib/mongoid/finders.rb,
lib/mongoid/indexes.rb,
lib/mongoid/scoping.rb,
lib/mongoid/version.rb,
lib/mongoid/copyable.rb,
lib/mongoid/criteria.rb,
lib/mongoid/document.rb,
lib/mongoid/equality.rb,
lib/mongoid/loggable.rb,
lib/mongoid/matchers.rb,
lib/mongoid/observer.rb,
lib/mongoid/paranoia.rb,
lib/mongoid/sessions.rb,
lib/mongoid/sharding.rb,
lib/mongoid/threaded.rb,
lib/mongoid/callbacks.rb,
lib/mongoid/evolvable.rb,
lib/mongoid/hierarchy.rb,
lib/mongoid/relations.rb,
lib/mongoid/reloading.rb,
lib/mongoid/attributes.rb,
lib/mongoid/components.rb,
lib/mongoid/contextual.rb,
lib/mongoid/inspection.rb,
lib/mongoid/timestamps.rb,
lib/mongoid/versioning.rb,
lib/mongoid/matchers/gt.rb,
lib/mongoid/matchers/in.rb,
lib/mongoid/matchers/lt.rb,
lib/mongoid/matchers/ne.rb,
lib/mongoid/matchers/or.rb,
lib/mongoid/persistence.rb,
lib/mongoid/validations.rb,
lib/mongoid/identity_map.rb,
lib/mongoid/matchers/all.rb,
lib/mongoid/matchers/and.rb,
lib/mongoid/matchers/gte.rb,
lib/mongoid/matchers/lte.rb,
lib/mongoid/matchers/nin.rb,
lib/mongoid/unit_of_work.rb,
lib/mongoid/matchers/size.rb,
lib/mongoid/relations/one.rb,
lib/mongoid/serialization.rb,
lib/mongoid/config/options.rb,
lib/mongoid/extensions/set.rb,
lib/mongoid/relations/many.rb,
lib/mongoid/errors/callback.rb,
lib/mongoid/extensions/date.rb,
lib/mongoid/extensions/hash.rb,
lib/mongoid/extensions/time.rb,
lib/mongoid/fields/standard.rb,
lib/mongoid/matchers/exists.rb,
lib/mongoid/relations/proxy.rb,
lib/mongoid/atomic/modifiers.rb,
lib/mongoid/contextual/eager.rb,
lib/mongoid/contextual/mongo.rb,
lib/mongoid/errors/no_parent.rb,
lib/mongoid/extensions/array.rb,
lib/mongoid/extensions/float.rb,
lib/mongoid/extensions/range.rb,
lib/mongoid/fields/localized.rb,
lib/mongoid/matchers/default.rb,
lib/mongoid/relations/cyclic.rb,
lib/mongoid/relations/macros.rb,
lib/mongoid/sessions/factory.rb,
lib/mongoid/timestamps/short.rb,
lib/mongoid/atomic/paths/root.rb,
lib/mongoid/contextual/atomic.rb,
lib/mongoid/contextual/memory.rb,
lib/mongoid/criterion/scoping.rb,
lib/mongoid/errors/eager_load.rb,
lib/mongoid/extensions/module.rb,
lib/mongoid/extensions/object.rb,
lib/mongoid/extensions/regexp.rb,
lib/mongoid/extensions/string.rb,
lib/mongoid/extensions/symbol.rb,
lib/mongoid/nested_attributes.rb,
lib/mongoid/railties/document.rb,
lib/mongoid/relations/binding.rb,
lib/mongoid/relations/builder.rb,
lib/mongoid/relations/options.rb,
lib/mongoid/config/environment.rb,
lib/mongoid/contextual/command.rb,
lib/mongoid/criterion/findable.rb,
lib/mongoid/errors/no_metadata.rb,
lib/mongoid/errors/validations.rb,
lib/mongoid/extensions/boolean.rb,
lib/mongoid/extensions/integer.rb,
lib/mongoid/fields/foreign_key.rb,
lib/mongoid/persistence/atomic.rb,
lib/mongoid/relations/builders.rb,
lib/mongoid/relations/metadata.rb,
lib/mongoid/sessions/mongo_uri.rb,
lib/mongoid/threaded/lifecycle.rb,
lib/mongoid/timestamps/created.rb,
lib/mongoid/timestamps/updated.rb,
lib/mongoid/validations/format.rb,
lib/mongoid/validations/length.rb,
lib/mongoid/validations/macros.rb,
lib/mongoid/atomic/positionable.rb,
lib/mongoid/attributes/readonly.rb,
lib/mongoid/contextual/geo_near.rb,
lib/mongoid/errors/invalid_find.rb,
lib/mongoid/errors/invalid_path.rb,
lib/mongoid/errors/invalid_time.rb,
lib/mongoid/matchers/strategies.rb,
lib/mongoid/relations/accessors.rb,
lib/mongoid/relations/auto_save.rb,
lib/mongoid/relations/cascading.rb,
lib/mongoid/relations/touchable.rb,
lib/mongoid/timestamps/timeless.rb,
lib/mongoid/contextual/queryable.rb,
lib/mongoid/criterion/inspection.rb,
lib/mongoid/criterion/modifiable.rb,
lib/mongoid/errors/invalid_field.rb,
lib/mongoid/errors/invalid_index.rb,
lib/mongoid/errors/invalid_scope.rb,
lib/mongoid/errors/mongoid_error.rb,
lib/mongoid/extensions/date_time.rb,
lib/mongoid/extensions/nil_class.rb,
lib/mongoid/extensions/object_id.rb,
lib/mongoid/persistence/deletion.rb,
lib/mongoid/relations/constraint.rb,
lib/mongoid/validations/presence.rb,
lib/mongoid/atomic/paths/embedded.rb,
lib/mongoid/attributes/processing.rb,
lib/mongoid/contextual/map_reduce.rb,
lib/mongoid/criterion/marshalable.rb,
lib/mongoid/errors/no_environment.rb,
lib/mongoid/extensions/true_class.rb,
lib/mongoid/persistence/insertion.rb,
lib/mongoid/persistence/upsertion.rb,
lib/mongoid/relations/conversions.rb,
lib/mongoid/relations/embedded/in.rb,
lib/mongoid/relations/marshalable.rb,
lib/mongoid/relations/polymorphic.rb,
lib/mongoid/relations/reflections.rb,
lib/mongoid/validations/queryable.rb,
lib/mongoid/errors/invalid_options.rb,
lib/mongoid/errors/mixed_relations.rb,
lib/mongoid/errors/scope_overwrite.rb,
lib/mongoid/extensions/big_decimal.rb,
lib/mongoid/extensions/false_class.rb,
lib/mongoid/persistence/atomic/bit.rb,
lib/mongoid/persistence/atomic/inc.rb,
lib/mongoid/persistence/atomic/pop.rb,
lib/mongoid/persistence/operations.rb,
lib/mongoid/relations/embedded/one.rb,
lib/mongoid/validations/associated.rb,
lib/mongoid/validations/uniqueness.rb,
lib/mongoid/errors/invalid_includes.rb,
lib/mongoid/errors/no_session_hosts.rb,
lib/mongoid/errors/unsaved_document.rb,
lib/mongoid/fields/validators/macro.rb,
lib/mongoid/persistence/atomic/pull.rb,
lib/mongoid/persistence/atomic/push.rb,
lib/mongoid/persistence/atomic/sets.rb,
lib/mongoid/relations/counter_cache.rb,
lib/mongoid/relations/embedded/many.rb,
lib/mongoid/relations/referenced/in.rb,
lib/mongoid/validations/localizable.rb,
lib/mongoid/config/validators/option.rb,
lib/mongoid/errors/inverse_not_found.rb,
lib/mongoid/errors/no_session_config.rb,
lib/mongoid/errors/unknown_attribute.rb,
lib/mongoid/persistence/atomic/unset.rb,
lib/mongoid/persistence/modification.rb,
lib/mongoid/relations/nested_builder.rb,
lib/mongoid/relations/referenced/one.rb,
lib/mongoid/timestamps/created/short.rb,
lib/mongoid/timestamps/updated/short.rb,
lib/mongoid/atomic/paths/embedded/one.rb,
lib/mongoid/config/validators/session.rb,
lib/mongoid/errors/delete_restriction.rb,
lib/mongoid/errors/document_not_found.rb,
lib/mongoid/errors/invalid_collection.rb,
lib/mongoid/errors/no_default_session.rb,
lib/mongoid/errors/no_sessions_config.rb,
lib/mongoid/errors/readonly_attribute.rb,
lib/mongoid/extensions/time_with_zone.rb,
lib/mongoid/persistence/atomic/rename.rb,
lib/mongoid/relations/referenced/many.rb,
lib/mongoid/relations/synchronization.rb,
lib/mongoid/atomic/paths/embedded/many.rb,
lib/mongoid/contextual/find_and_modify.rb,
lib/mongoid/errors/no_session_database.rb,
lib/mongoid/indexes/validators/options.rb,
lib/mongoid/multi_parameter_attributes.rb,
lib/mongoid/relations/cascading/delete.rb,
lib/rails/generators/mongoid_generator.rb,
lib/mongoid/contextual/aggregable/mongo.rb,
lib/mongoid/errors/invalid_field_option.rb,
lib/mongoid/errors/no_map_reduce_output.rb,
lib/mongoid/persistence/atomic/pull_all.rb,
lib/mongoid/persistence/atomic/push_all.rb,
lib/mongoid/relations/cascading/destroy.rb,
lib/mongoid/relations/cascading/nullify.rb,
lib/mongoid/sessions/validators/storage.rb,
lib/mongoid/contextual/aggregable/memory.rb,
lib/mongoid/errors/invalid_config_option.rb,
lib/mongoid/persistence/atomic/operation.rb,
lib/mongoid/relations/cascading/restrict.rb,
lib/mongoid/relations/embedded/batchable.rb,
lib/mongoid/relations/targets/enumerable.rb,
lib/mongoid/errors/ambiguous_relationship.rb,
lib/mongoid/errors/unsupported_javascript.rb,
lib/mongoid/errors/versioning_not_on_root.rb,
lib/mongoid/persistence/atomic/add_to_set.rb,
lib/mongoid/persistence/operations/insert.rb,
lib/mongoid/persistence/operations/remove.rb,
lib/mongoid/persistence/operations/update.rb,
lib/mongoid/persistence/operations/upsert.rb,
lib/mongoid/errors/invalid_storage_options.rb,
lib/mongoid/relations/bindings/embedded/in.rb,
lib/mongoid/relations/builders/embedded/in.rb,
lib/mongoid/relations/bindings/embedded/one.rb,
lib/mongoid/relations/builders/embedded/one.rb,
lib/mongoid/relations/bindings/embedded/many.rb,
lib/mongoid/relations/bindings/referenced/in.rb,
lib/mongoid/relations/builders/embedded/many.rb,
lib/mongoid/relations/builders/referenced/in.rb,
lib/mongoid/relations/bindings/referenced/one.rb,
lib/mongoid/relations/builders/referenced/one.rb,
lib/mongoid/relations/referenced/many_to_many.rb,
lib/mongoid/errors/mixed_session_configuration.rb,
lib/mongoid/relations/bindings/referenced/many.rb,
lib/mongoid/relations/builders/referenced/many.rb,
lib/mongoid/persistence/operations/embedded/insert.rb,
lib/mongoid/persistence/operations/embedded/remove.rb,
lib/rails/generators/mongoid/model/model_generator.rb,
lib/mongoid/errors/invalid_set_polymorphic_relation.rb,
lib/mongoid/errors/too_many_nested_attribute_records.rb,
lib/mongoid/relations/builders/nested_attributes/one.rb,
lib/rails/generators/mongoid/config/config_generator.rb,
lib/mongoid/relations/builders/nested_attributes/many.rb,
lib/mongoid/relations/bindings/referenced/many_to_many.rb,
lib/mongoid/relations/builders/referenced/many_to_many.rb,
lib/mongoid/errors/nested_attributes_metadata_not_found.rb,
lib/rails/generators/mongoid/observer/observer_generator.rb

Defined Under Namespace

Modules: Atomic, Attributes, Callbacks, Components, Config, Contextual, Copyable, Criterion, Dirty, Document, Equality, Errors, Evolvable, Extensions, Factory, Fields, Finders, Generators, Hierarchy, Indexes, Inspection, JSON, Loggable, Matchers, MultiParameterAttributes, NestedAttributes, Paranoia, Persistence, Relations, Reloading, Scoping, Serialization, Sessions, Sharding, State, Threaded, Timestamps, UnitOfWork, Validations, Versioning Classes: Criteria, IdentityMap, Observer

Constant Summary collapse

MONGODB_VERSION =
"2.0.0"
VERSION =
"3.1.6"

Instance Method Summary collapse

Methods included from Loggable

logger, logger=

Methods included from UnitOfWork

unit_of_work, using_identity_map?

Instance Method Details

#configureConfig

Sets the Mongoid configuration options. Best used by passing a block.

Examples:

Set up configuration options.

Mongoid.configure do |config|
  config.allow_dynamic_fields = false
  config.use(name: "mongoid_test", host: "localhost", port: 27017)
end

Returns:

  • (Config)

    The configuration object.

Since:

  • 1.0.0



116
117
118
# File 'lib/mongoid.rb', line 116

def configure
  block_given? ? yield(Config) : Config
end

#default_sessionMoped::Session

Convenience method for getting the default session.

Examples:

Get the default session.

Mongoid.default_session

Returns:

  • (Moped::Session)

    The default session.

Since:

  • 3.0.0



128
129
130
# File 'lib/mongoid.rb', line 128

def default_session
  Sessions.default
end

#disconnect_sessionstrue

Disconnect all active sessions.

Examples:

Disconnect all active sessions.

Mongoid.disconnect_sessions

Returns:

  • (true)

    True.

Since:

  • 3.1.0



140
141
142
# File 'lib/mongoid.rb', line 140

def disconnect_sessions
  Sessions.disconnect
end

#session(name) ⇒ Moped::Session

Convenience method for getting a named session.

Examples:

Get a named session.

Mongoid.session(:default)

Returns:

  • (Moped::Session)

    The named session.

Since:

  • 3.0.0



152
153
154
# File 'lib/mongoid.rb', line 152

def session(name)
  Sessions.with_name(name)
end