All Versions
Latest Version
Avg Release Cycle
24 days
Latest Release
663 days ago

Changelog History
Page 2

  • v5.0.2

  • v5.0.1 Changes

    Resolved Issues

  • v5.0.0 Changes

    Major Changes (Backwards Incompatible)

    • 💎 Mongoid now uses the official Mongo Ruby Driver 2.x instead of Moped.

    • 👀 Most driver specific configuration options have changed, please see here for the new options.

    • 🔧 All references to session are now replaced with client. This includes the mongoid.yml configuration, store_in options, and all exceptions and modules with Session in the name.

    • find_and_modify has been removed and replaced with 3 options: find_one_and_update, find_one_and_delete and find_one_and_replace.

    • 🚚 text_search has been removed as it is now a $text option in a query from 2.6 on.

    • 👍 Mongoid no longer supports MongoDB 2.2 - support is now for only 2.4 and higher.

    • #3768 first and last no longer add an _id sort when no sorting options have been provided. In order to guarantee that a document is the first or last, it needs to now contain an explicit sort.

    • 🚚 Document#deleted? alias has been removed, please continue to use Document#destroyed?.

    🆕 New Features

    • #4016 Allow private and protected setters on fields for atomic operations. (Rob Smith)

    • #3985 Return nil when using {upsert: true} in find_and_modify (Adrien Siami)

    • #3963 Allow extended JSON object ids to be passed to find.

    • #3846 Allow #pluck when none is used in criteria. (Braulio Martinez)

    Resolved Issues

    • #4091 Use sublcass context when calling a scope defined in a superclass. (Edgars Beigarts)

    • 🚚 #4075 Made remove index logging specific to each index that was actually getting removed.

    • 🛠 #4071 Fixed loading of enumerable relation to check the added documents when iterating.

    • #4077 Many relations now include Enumerable.

    • 🛠 #4052 Fixed uniqueness validation on localized fields with no value.

    • ⚡️ #4033 Removed all uses of the $ positional operator in atomic updates.

    • 👯 #4030 Dup/clone exceptions auto-include dynamic attributes.

    • 🚅 #4005 Fixed inclusion of mongoid with Rails components that don't have the Rails environment.

    • 👯 #3993 Fixes issue where dup/clone fails for embedded documents that use store_as without using Mongoid::Atributes::Dynamic

    • 🛠 #3991 Fixed emebdded documents not flagging as changed after calling #changed? and modifying the child elements.

    • #3874 Adding snapshot option to context.

    • 🚅 #3868 Loading models in rake tasks now expands the rails path.

    • 🛠 #3764 Fixed case statement check for enumerable targets.

    • 🛠 #3740 Fixes Missing attribute: '_id' error when using methods only or without (dx7)

    • 🛠 #3631 Fixes issue where before_save callback can get called twice after a child create

    • 0️⃣ #3599 Fixed application of default scopes from superclass in subclasses.

    • 🛠 #3104 Fixed enumerable targets to check first/last in proper order.

  • v4.0.2 Changes

    🆕 New Features

    • #3931 Add #find_or_create_by! method to many associations. (Tom Beynon)

    • #3731 Add find_by! method. (Guillermo Iguaran)

    Resolved Issues

    • #3722 Use the right database name when combining #store_in and #with. (Arthur Neves)

    • #3934 Dont apply sort when doing a find_by. (Arthur Neves)

    • #3935 fix multiple fields sorting on contextual memory. (chamnap)

    • #3904 BSON::Document#symbolize_keys should return keys as symbols. (Arthur Neves)

    • #3948 Fix remove_undefined_indexes on rails 4.2, to symbolize right the Document keys. (Adam Wróbel)

    • #3626 Document#to_key, needs to return a ObjectId as String so we can query back using that id. (Arthur Neves)

    • #3888 raise UnknownAttributeError when 'set' is called on non existing field and Mongoid::Attributes::Dynamic is not included in model. (Shweta Kale)

    • #3889 'set' will allow to set value of non existing field when Mongoid::Attributes::Dynamic is included in model. (Shweta Kale)

    • 🛠 #3812 Fixed validation context when saving (Yaroslav Zemlyanuhin)

  • v4.0.1 Changes

    Resolved Issues

    • #3911 Fix relations named "parent". (nkriege)

    • #3792/#3881 Fix many internal calls to #_id instead of #id to avoid issues when overloading #id (Gauthier Delacroix)

    • #3847 Fix 'QueryCache#get_more' result, when collection has more documents than first query batch. (Angelica Korsun)

    • #3684 Dont raise MissingAttributeError, when using a only() scope. (Arthur Neves)

    • #3703 pluck method should not compact the values. (Arthur Neves)

    • #3773 Use nanoseconds for cache_key timestamp instead of plain seconds. (Máximo Mussini)

  • v4.0.0 Changes

    Major Changes (Backwards Incompatible)

    • 🚚 #3320 Remove Rails dependencies on database rake tasks. (Arthur Neves)

      All db:* rake tasks should work as before when using Rails. When not in a Rails, just load the database tasks using:

      load 'mongoid/tasks/database.rake'
    • 👍 Mongoid 4 now only supports MongoDB 2.4.0 and higher.

    • 📇 Document#metadata has been renamed to Document#relation_metadata to avoid common conflicts. Relation proxies also have this renamed to the same as well.

    • 0️⃣ Scopes and default scopes must now all be defined within lambdas or procs.

    • 🔖 skip_version_check config option was removed.

    • 🚚 IdentityMap removed. (Arthur Neves)

    • Eager load rework. Eager load now doesnt need the identity map to load related documents. A set of preloaders can eager load the associations passed to .includes method. (Arthur Neves)

    • 👍 Mongoid now supports the new read preferences that the core drivers provide. These include:

      • :primary: Will always read from a primary node. (default)
      • :primary_preferred: Attempt a primary first, then secondary if none available.
      • :secondary: Will always read from a secondary node.
      • :secondary_preferred: Attempt a secondary first, then primary if none available.
      • :nearest: Attempt to read from the node with the lowest latency.

      Sample syntax:

      Person.with(read: :secondary).first

      The :consistency option is no longer valid, use the :read option now.

    • 0️⃣ Mongoid now defaults all writes to propagate (formerly "safe mode") and now has different propagate semantics:

      • { w: -1 }: Don't verify writes and raise no network errors.
      • { w: 0 }: Don't verify writes and raise network errors.
      • { w: 1 }: Verify writes on the primary node. (default)
      • { w: n }: Verify writes on n number of nodes.
      • { w: "majority" }: Verify writes on a majority of nodes.

      Sample syntax:

      Person.with(write: {w: :majority}).create!(name: "John")

      The :safe option is no longer valid use the :write option now.

    • #3230 Array and Hash fields now validate that the correct types are getting set, instead of allowing any value. (Rodrigo Saito)

    • #3043/#2949 Rework on the internals of persistence options. (Arthur Neves)

    • Mongoid now requires Active Model 4 or higher.

    • Document#set now accepts multiple attributes in the form of a hash, instead of the previous (field, value) args. Field aliases and typecasting are also now supported in this operation.

      document.set(name: "Photek", likes: 10000)
    • Document#rename now accepts multiple attributes in the form of a hash, instead of the previous (field, value) args. Field aliases are supported.

      document.rename(first_name: "fn", last_name: "ln")
    • Document#inc now accepts multiple attributes in the form of a hash, instead of previously only being able to increment one value at a time. Aliases and serialization is supported. 10, place: -1, lives: -10)
    • Document#pop now accepts multiple attributes in the form of a hash, instead of previously only being able to pop one value at a time. Aliases and serialization is supported.

      document.pop(names: 1, aliases: -1)
    • Document#bit now accepts multiple attributes in the form of a hash, instead of previously only being able to apply one set of operations at a time. Aliases and serialization are supported.

      document.bit(age: { and: 13 }, score: { or: 13 })
    • Document#pull now accepts multiple attributes in the form of a hash, instead of previously only being able to pull one value at a time. Aliases and serialization is supported.

      document.pull(names: "James", aliases: "007")
    • Document#pull_all now accepts multiple attributes in the form of a hash, instead of previously only being able to pull one value at a time. Aliases and serialization is supported.

      document.pull_all(names: ["James", "Bond"], aliases: ["007"])
    • 🚚 Document#push_all has been removed since it was deprecated in MongoDB 2.4. Use Document.push instead.

    • Document#push now accepts multiple attributes in the form of a hash, and can handle the pushing of single values or multiple values to the field via $push with $each. Aliases and serialization is supported.

      document.push(names: "James", aliases: [ "007", "Jim" ])
    • Document#add_to_set now accepts multiple attributes in the form of a hash, and now aliases and serialization are supported.

      document.add_to_set(names: "James", aliases: "007")
    • Criteria atomic operations API is now changed to match the changes in the single document atomic API, for example:

      Band.where(name: "Depeche Mode").inc(likes: 10, followers: 20)
    • #3399 #create and #create! on relations can now take an array of attributes as the first parameter to create multiple documents at once.

      person.addresses.create([{ street: "Bond" }, { street: "Upper" }])
      person.addresses.create!([{ street: "Bond" }, { street: "Upper" }])
    • ✅ #3141 rake db:test:prepare now sets up all defined indexes if Mongoid is the only ODM/ORM in the environment.

    • ⚡️ #3138 update_attributes can now be accessed simply by calling update.

    • #3083 A new rake task: rake db:mongoid:remove_undefined_indexes has been added to remove indexes from the database that are not explicitly defined in the models. (Aidan Feldman)

    • #3029 The relation_field field that is added for a single use case with polymorphic relations has been removed. So where the following would work before:

      class Eye
        include Mongoid::Document
        belongs_to :eyeable, polymorphic: true
      class Face
        include Mongoid::Document
        has_one :left_eye, class_name: "Eye", as: :eyeable
        has_one :right_eye, class_name: "Eye", as: :eyeable

      This would now need to be modeled as (with the appropriate migration):

      class Eye
        include Mongoid::Document
        belongs_to :left_socket, class_name: "Face", inverse_of: :left_eye
        belongs_to :right_socket, class_name: "Face", inverse_of: :right_eye
      class Face
        include Mongoid::Document
        has_one :left_eye, class_name: "Eye", inverse_of: :left_socket
        has_one :right_eye, class_name: "Eye", inverse_of: :right_socket
    • ⚡️ #3075 update_attribute now properly calls the setter method instead of using write_attribute.

    • #3060 Allow atomically blocks to allow multiple calls of the same type. (Brian Norton)

    • #3037 Model indexes are no longer stored in an index_options hash on the model class. Instead, an array named index_specifications now exists on the class which contains a list of Indexable::Specification objects. This is so we could properly handle the case of indexes with the same keys but different order.

    • #2956 Caching on queries now only happens when cache is specifically called. (Arthur Neves)

    • #2659 Mongoid::Railtie now properly uses only one initializer and the name has changed to mongoid.load-config.

    • 👀 #2656 rake db:reseed is now rake db:reset (Arthur Neves)

    • #2648 Boolean becomes Mongoid::Boolean to avoid polluting the global namespace with a commonly used class by other libraries.

    • #2603 Return values from setters are now always the set value, regardless of calling the setter or using send.

    • 🚚 #2597 Mongoid::Observer was removed in line with Rails 4.

    • #2563 The allow_dynamic_fields configuration option has been removed as dynamic fields are now allowed on a per-model level. In order to allow a model to use dynamic fields, simply include the module in each. (Josh Martin)

      class Band
        include Mongoid::Document
        include Mongoid::Attributes::Dynamic
    • #2497 Calling to_json no longer tampers with the return value from the driver, and proper returns { "$oid" : object_id.to_s } instead of just the string representation previously.

    • 🚚 #2433 Mongoid::Paranoia has been removed.

    • 🚚 #2432 Mongoid::Versioning has been removed.

    • 0️⃣ #2218 Creating or instantiating documents that have default scopes will now apply the default scope to the document, if the scope is not complex.

    • 🔒 #2200 Mass assignment security now mirrors Rails 4's behavior. without_protection option was also removed. attr_accessible class method was removed. Mongoid and Strong parameters should work fine for mass assignment protection.

    • delete_all and destroy_all no longer take a :conditions hash but just the raw attributes.

    • #1908 Documents now loaded from criteria using #only or #without will now raise an error when attempting to save, update, or delete these records. Additionally fields excluded from the fields retrieved from the database will also raise an exception when trying to access them.

    • ⚡️ #1344 Atomic updates can now be executed in an atomically block, which will delay any atomic updates on the document the block was called on until the block is complete.

      Update calls can be executed as normal in the block:

      document.atomically do 10)
        document.bit(members: { and: 10 })
        document.set(name: "Photek")

      The document is also yielded to the block:

      document.atomically do |doc| 10)
        doc.bit(members: { and: 10 })
        doc.set(name: "Photek")

      The atomic commands are have a fluid interface:

      document.atomically do |doc| 10).bit(members: { and: 10 }).set(name: "Photek")

      If the fluid interface is leveraged without the atomically block, the operations will persist in individual calls. For example, the following would hit the database 3 times without the block provided: 10).bit(members: { and: 10 }).set(name: "Photek")

      The block is only good for 1 document at a time, so embedded and root document updates cannot be mixed at this time.

    🆕 New Features

    • 🔊 Mongoid now uses ActiveSupport::LogSubscriber to subscribe logs, and ActiveSupport::Notifications to send operation logs. (Arthur Neves) Example of log subscription:

      ActiveSupport::Notifications.subscribe('query.moped') do |event| .. end

    • 👀 Field types can now use symbols as well as class names. See: for the available mappings.

    • 0️⃣ #3580 Fields can now be reset to their default values, with the methods:


    • #3513 Documents now have a #destroy! method that will raise a Mongoid::Errors::DocumentNotDestroyed error if a destroy callback returns a false value.

    • #3496 Added class level and criteria level find_or_create_by!.

    • ⏱ #3479 Map/reduce now respects criteria no timeout options if output is not inline.

    • #3478 Criteria objects now have a #none method that will cause the criteria to never hit the database and always have zero documents.

      Band.none Band.none.where(name: "Tool") # Always has zero documents.

    • #3410 Mongoid now has a query cache that can be used as a middleware in Rack applications. (Arthur Neves)

      For Rails:


    • #3319 Counters can now be reset from a document instance:


    • ⚡️ #3310 embedded_in relations now accept a touch option to update parents.

    • #3302 Aliasing using alias_attribute now properly handles aliases in criteria.

    • #3155 Range field will persist the exclude_end when provided. (Daniel Libanori)

    • #3146 Adding :overwrite field option, when it`s true, it wont check duplicates. (Daniel Libanori)

    • 🚅 #3002 Reloading the Rails console will also now clear Mongoid's identity map.

    • #2938 A configuration option duplicate_fields_exception has been added that when set to true will raise an exception when defining a field that will override an existing method. (Arthur Neves)

    • #2924 MongoDB 2.4 beta text search now has a DSL provided by Mongoid. Like other queries, text searches are lazy evaluated, and available off the class or criteria level.

      Note that any 3rd party gem that provides a text_search method will now no longer work with Mongoid, and will need to change its syntax. Examples:

      Band.text_search("mode").project(name: 1).each do |doc|
        # ...
      Band.where( => 1000).text_search("lucy")
    • #2855 Multiple extensions can now be supplied to relations. (Daniel Libanori)

    Resolved Issues

    • #3676 Make pluck work with embedded associations (Arthur Neves)

    • #2898 Dirty attribute methods now properly handle field aliases. (Niels Ganser)

    • #3620 Add ActiveModel module instance methods to prohibited_methods list. (Arthur Neves)

    • #3610 Don't allow atomic operations on read-only attributes (Frederico Araujo)

    • #3619 Don't validate documents that are flagged for destruction. (Christopher J. Bottaro)

    • #3617 Don't skip index creation on cyclic documents. (shaiker)

    • 🛠 #3568 Fixed missing attributes error on present localized fields.

    • 🛠 #3514 Fixed query cache to work on first/last calls.

    • #3383/#3495 Fix has_and_belongs_to_many eager load. (Arthur Neves)

    • #3492 $rename operations should not mongoize values. (Vladislav Melanitskiy)

    • #3490 Allow localized fields to work with boolean false values.

    • #3487 Map Boolean to Mongoid::Boolean in field definitions. (Arthur Neves)

    • ⚡️ #3449 Touch needs to work for create and update. (Greggory Rothmeier)

    • #3347 Creating documents off of scopes for embedded relations now properly sets the parent document on the created children.

    • 🛠 #3432 Fixed mongoization of DateTime losing precision.

    • 🛠 #3397 Fixed $ne matcher for embedded documents to match server behavior.

    • #3352 Allow named scopes named "open" to work through 1-n relations.

    • #3348 Fixing compounded indexes having the same keys with different directions. (Arthur Neves)

    • #2701 Fixing extra query on belongs_to binding. (Arthur Neves)

    • #3089 Allow demongoization of strings to floats (Daniel Libanori)

    • ⚡️ #3278 Counter cache should update the document in memory too. (Arthur Neves)

    • #3242 Has_many relation must use the inverse foreign_key. (Arthur Neves)

    • #3233 Don't double call validation callbacks when cascading children and relation validation is turned on.

    • #3197 Improvements in the calls to aggregates on root and embedded collections. (Wojciech Piekutowski)

    • #3144/#3219 Fixing name colission on @_children ivar. (Arthur Neves)

    • #3088 Range field can accept a hash, which could be the attribute from the db. (Daniel Libanori)

    • 🛠 #3116 Relations instance variables are now all prefixed with _.

    • #3093 Only flatten 1 level when atomically pushing arrays.

    • #3063 Document#becomes now properly sets base object on errors. (Adam Ross Cohen)

    • #3019 Atomic operations will no longer attempt to persist if the document is not persisted.

    • 🚚 #2903 Removed unused string to_a extension.

  • v3.1.7 Changes

    Resolved Issues

    • 🛠 #3465 Fixed ambigous relation errors where inverse_of is set to nil.

    • #3414 Backkport skip and limit options on aggregation. (Wojciech Piekutowski)

    • #3469 Fix RegexpError: failed to allocate memory: /./ on .hash_dot_syntax? (Dmitry Krasnoukhov)

  • v3.1.6 Changes

    Resolved Issues

    • 👯 #3337 Ensure localized fields map is cloned with inheritance.

    • 🛠 #3262 Fixed atomic array operations on HABTM foreign key fields from turning single elements into arrays.

    • 🛠 #3282 Fixed .timeless option to use a thread local instead of a class attribute. Also remove the timeless methods from all docs, and only add to timestamps docs. (Arthur Neves)

  • v3.1.5 Changes

    Resolved Issues

    • #3231 Allow evolution of proxy documents to work in criteria.

    • #3247 Bump dependency on tzinfo to 0.3.29.

    • 🛠 #3203 Fixed index: true specification for polymorphic relations.

    • 🛠 #3192 Fixed aliased fields + localized fields combinations with validation. (Johnny Shields)

    • 🛠 #3173 Fixed issues around many to many relations with custom primary keys. (Bowen Sun)

    • #3159 Upserting now properly flags documents as persisted.

    • #3137 Allow multiple belongs_to sets in a row with ids.

    • 📄 #3079 Embedded docs with paranoia parents were losing the _id when reloading from db, as they didnt have the right persisted? value. (Arthur Neves)

    • #3081 Criteria's method_missing now checks if an array responds to the provided method before calling entries in order to not hit the database if a NoMethodError was to get raised.

    • #3068 Fixed spec runs on non standard MongoDB ports if MONGOID_SPEC_PORT is set.

    • #3047 Ensure blank? and empty? don't fall through method missing on criteria.

    • Include updated_at on cache_key even when is a short timestamp (Arthur Neves)

  • v3.1.4 Changes

    Resolved Issues

    • #3044 Ensure enumerable targets match arrays in case statements.

    • #3034 first_or_create on criterion now properly passes the block to create instead of calling after the document was created.

    • 🚚 #3021 Removed mongoid.yml warning from initializer, this is now handled by the session configuration options.

    • #3018 Uniqueness validator now properly serializes values in its check. (Jerry Clinesmith)

    • 🛠 #3011 Fixed aliased field support for uniqueness validation. (Johnny Shields)

    • 🛠 #3008 Fixed subclasses not being able to inherit scopes properly when scope is added post class load. (Mike Dillon)

    • #2991 Document.timeless now properly scopes to the instance and not thread.

    • #2980 Dynamic fields now properly handle in place editing of hashes and arrays. (Matthew Widmann)

    • #2979 pluck no longer modifies the context in place. (Brian Goff)

    • 🛠 #2970 Fixed counter cache to properly use the name of the relation if available then the inverse class name second if not.

    • #2959 Nested attributes will now respect autosave: false if defined on the relation.

    • 🛠 #2944 Fixed uniqueness validation for localized fields when case insensitive is true. (Vladimir Zhukov)