Module: Mongoid

Extended by:
Mongoid
Included in:
Mongoid
Defined in:
lib/mongoid.rb,
lib/mongoid/json.rb,
lib/mongoid/keys.rb,
lib/mongoid/dirty.rb,
lib/mongoid/scope.rb,
lib/mongoid/state.rb,
lib/mongoid/atomic.rb,
lib/mongoid/config.rb,
lib/mongoid/cursor.rb,
lib/mongoid/extras.rb,
lib/mongoid/fields.rb,
lib/mongoid/logger.rb,
lib/mongoid/safety.rb,
lib/mongoid/factory.rb,
lib/mongoid/finders.rb,
lib/mongoid/indexes.rb,
lib/mongoid/version.rb,
lib/mongoid/contexts.rb,
lib/mongoid/copyable.rb,
lib/mongoid/criteria.rb,
lib/mongoid/document.rb,
lib/mongoid/identity.rb,
lib/mongoid/matchers.rb,
lib/mongoid/observer.rb,
lib/mongoid/paranoia.rb,
lib/mongoid/sharding.rb,
lib/mongoid/threaded.rb,
lib/mongoid/callbacks.rb,
lib/mongoid/hierarchy.rb,
lib/mongoid/relations.rb,
lib/mongoid/reloading.rb,
lib/mongoid/attributes.rb,
lib/mongoid/collection.rb,
lib/mongoid/components.rb,
lib/mongoid/inspection.rb,
lib/mongoid/javascript.rb,
lib/mongoid/timestamps.rb,
lib/mongoid/versioning.rb,
lib/mongoid/collections.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/named_scope.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/default_scope.rb,
lib/mongoid/matchers/size.rb,
lib/mongoid/relations/one.rb,
lib/mongoid/serialization.rb,
lib/mongoid/contexts/mongo.rb,
lib/mongoid/multi_database.rb,
lib/mongoid/relations/many.rb,
lib/mongoid/config/database.rb,
lib/mongoid/errors/callback.rb,
lib/mongoid/fields/mappings.rb,
lib/mongoid/matchers/exists.rb,
lib/mongoid/relations/proxy.rb,
lib/mongoid/atomic/modifiers.rb,
lib/mongoid/matchers/default.rb,
lib/mongoid/relations/cyclic.rb,
lib/mongoid/relations/macros.rb,
lib/mongoid/atomic/paths/root.rb,
lib/mongoid/collections/retry.rb,
lib/mongoid/criterion/builder.rb,
lib/mongoid/criterion/complex.rb,
lib/mongoid/errors/eager_load.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/collections/master.rb,
lib/mongoid/criterion/optional.rb,
lib/mongoid/criterion/selector.rb,
lib/mongoid/errors/validations.rb,
lib/mongoid/persistence/atomic.rb,
lib/mongoid/relations/builders.rb,
lib/mongoid/relations/metadata.rb,
lib/mongoid/threaded/lifecycle.rb,
lib/mongoid/timestamps/created.rb,
lib/mongoid/timestamps/updated.rb,
lib/mongoid/contexts/enumerable.rb,
lib/mongoid/criterion/exclusion.rb,
lib/mongoid/criterion/inclusion.rb,
lib/mongoid/errors/invalid_find.rb,
lib/mongoid/errors/invalid_time.rb,
lib/mongoid/errors/invalid_type.rb,
lib/mongoid/fields/serializable.rb,
lib/mongoid/matchers/strategies.rb,
lib/mongoid/relations/accessors.rb,
lib/mongoid/relations/auto_save.rb,
lib/mongoid/relations/cascading.rb,
lib/mongoid/timestamps/timeless.rb,
lib/mongoid/criterion/creational.rb,
lib/mongoid/criterion/inspection.rb,
lib/mongoid/errors/invalid_field.rb,
lib/mongoid/errors/mongoid_error.rb,
lib/mongoid/persistence/deletion.rb,
lib/mongoid/relations/constraint.rb,
lib/mongoid/atomic/paths/embedded.rb,
lib/mongoid/attributes/processing.rb,
lib/mongoid/persistence/insertion.rb,
lib/mongoid/relations/conversions.rb,
lib/mongoid/relations/embedded/in.rb,
lib/mongoid/relations/polymorphic.rb,
lib/mongoid/relations/reflections.rb,
lib/mongoid/collections/operations.rb,
lib/mongoid/errors/invalid_options.rb,
lib/mongoid/errors/mixed_relations.rb,
lib/mongoid/extensions/object/yoda.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/config/replset_database.rb,
lib/mongoid/errors/invalid_database.rb,
lib/mongoid/errors/unsaved_document.rb,
lib/mongoid/extensions/hash/scoping.rb,
lib/mongoid/extensions/proc/scoping.rb,
lib/mongoid/fields/serializable/set.rb,
lib/mongoid/persistence/atomic/pull.rb,
lib/mongoid/persistence/atomic/push.rb,
lib/mongoid/persistence/atomic/sets.rb,
lib/mongoid/relations/embedded/many.rb,
lib/mongoid/relations/embedded/sort.rb,
lib/mongoid/relations/referenced/in.rb,
lib/mongoid/contexts/enumerable/sort.rb,
lib/mongoid/extensions/object/checks.rb,
lib/mongoid/extensions/string/checks.rb,
lib/mongoid/extensions/symbol/checks.rb,
lib/mongoid/fields/serializable/date.rb,
lib/mongoid/fields/serializable/hash.rb,
lib/mongoid/fields/serializable/time.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/atomic/paths/embedded/one.rb,
lib/mongoid/errors/document_not_found.rb,
lib/mongoid/errors/invalid_collection.rb,
lib/mongoid/extensions/array/deletion.rb,
lib/mongoid/extensions/integer/checks.rb,
lib/mongoid/fields/serializable/array.rb,
lib/mongoid/fields/serializable/float.rb,
lib/mongoid/fields/serializable/range.rb,
lib/mongoid/persistence/atomic/rename.rb,
lib/mongoid/relations/embedded/atomic.rb,
lib/mongoid/relations/referenced/many.rb,
lib/mongoid/relations/synchronization.rb,
lib/mongoid/atomic/paths/embedded/many.rb,
lib/mongoid/errors/unsupported_version.rb,
lib/mongoid/fields/serializable/bignum.rb,
lib/mongoid/fields/serializable/binary.rb,
lib/mongoid/fields/serializable/fixnum.rb,
lib/mongoid/fields/serializable/object.rb,
lib/mongoid/fields/serializable/string.rb,
lib/mongoid/fields/serializable/symbol.rb,
lib/mongoid/multi_parameter_attributes.rb,
lib/mongoid/relations/cascading/delete.rb,
lib/mongoid/relations/referenced/batch.rb,
lib/rails/generators/mongoid_generator.rb,
lib/mongoid/fields/serializable/boolean.rb,
lib/mongoid/fields/serializable/integer.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/persistence/atomic/operation.rb,
lib/mongoid/relations/cascading/strategy.rb,
lib/mongoid/relations/targets/enumerable.rb,
lib/mongoid/extensions/object/reflections.rb,
lib/mongoid/extensions/string/conversions.rb,
lib/mongoid/extensions/string/inflections.rb,
lib/mongoid/extensions/symbol/inflections.rb,
lib/mongoid/fields/serializable/date_time.rb,
lib/mongoid/fields/serializable/localized.rb,
lib/mongoid/fields/serializable/nil_class.rb,
lib/mongoid/fields/serializable/object_id.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/relations/embedded/atomic/set.rb,
lib/mongoid/extensions/true_class/equality.rb,
lib/mongoid/relations/bindings/embedded/in.rb,
lib/mongoid/relations/builders/embedded/in.rb,
lib/mongoid/relations/embedded/atomic/pull.rb,
lib/mongoid/extensions/false_class/equality.rb,
lib/mongoid/extensions/object/substitutable.rb,
lib/mongoid/fields/serializable/big_decimal.rb,
lib/mongoid/fields/serializable/timekeeping.rb,
lib/mongoid/relations/bindings/embedded/one.rb,
lib/mongoid/relations/builders/embedded/one.rb,
lib/mongoid/relations/embedded/atomic/unset.rb,
lib/mongoid/extensions/hash/criteria_helpers.rb,
lib/mongoid/extensions/nil/collectionization.rb,
lib/mongoid/extensions/object_id/conversions.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/batch/insert.rb,
lib/mongoid/relations/referenced/many_to_many.rb,
lib/mongoid/fields/serializable/time_with_zone.rb,
lib/mongoid/relations/bindings/referenced/many.rb,
lib/mongoid/relations/builders/referenced/many.rb,
lib/mongoid/relations/embedded/atomic/push_all.rb,
lib/mongoid/relations/embedded/atomic/operation.rb,
lib/mongoid/fields/serializable/foreign_keys/array.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/fields/serializable/foreign_keys/object.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/rails/generators/mongoid/observer/observer_generator.rb

Overview

:nodoc:

Defined Under Namespace

Modules: Atomic, Attributes, Callbacks, Collections, Components, Config, Contexts, Copyable, Criterion, DefaultScope, Dirty, Document, Errors, Extensions, Extras, Factory, Fields, Finders, Generators, Hierarchy, Indexes, Inspection, JSON, Keys, Matchers, MultiDatabase, MultiParameterAttributes, NamedScope, NestedAttributes, Paranoia, Persistence, Relations, Reloading, Safety, Serialization, Sharding, State, Threaded, Timestamps, Validations, Versioning Classes: Collection, Criteria, Cursor, Identity, IdentityMap, Javascript, Logger, Observer, Scope

Constant Summary collapse

MONGODB_VERSION =
"2.0.0"
VERSION =
"3.0.0"

Instance Method Summary collapse

Instance Method Details

#configureConfig Also known as: config

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

Examples:

Set up configuration options.

Mongoid.configure do |config|
  name = "mongoid_test"
  host = "localhost"
  config.allow_dynamic_fields = false
  config.master = Mongo::Connection.new.db(name)
end

Returns:

  • (Config)

    The configuration obejct.

Since:

  • 1.0.0



114
115
116
# File 'lib/mongoid.rb', line 114

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

#unit_of_workObject

We can process a unit of work in Mongoid and have the identity map automatically clear itself out after the work is complete.

Examples:

Process a unit of work.

Mongoid.unit_of_work do
  Person.create(:title => "Sir")
end

Returns:

  • (Object)

    The result of the block.

Since:

  • 2.1.0



130
131
132
133
134
135
136
# File 'lib/mongoid.rb', line 130

def unit_of_work
  begin
    yield if block_given?
  ensure
    IdentityMap.clear
  end
end