Skip to content

Releases: mongodb/mongoid

9.1.0

Choose a tag to compare

@mongodb-dbx-release-bot mongodb-dbx-release-bot released this 08 May 14:05
fc21c41

The MongoDB Ruby team is pleased to announce version 9.1.0 of the mongoid gem - an Ruby ODM for MongoDB. This is a new minor release in the 9.x series of Mongoid.

Install this release using RubyGems via the command line as follows:

gem install -v 9.1.0 mongoid

Or simply add it to your Gemfile:

gem 'mongoid', '9.1.0'

Have any feedback? Click on through to MongoDB's JIRA and open a new ticket to let us know what's on your mind 🧠.

New Features

MONGOID-5411 allow results to be returned as demongoized hashes (PR)

Mongoid now supports a new raw directive when building queries. When present, the resulting query will be returned as hashes, rather than instantiated document models. The hashes will not be "demongoized" -- the values will be returned exactly as provided by the database, directly.

If you specify typed: true, the hashes will be returned with the values translated from the raw value stored in the database, into the corresponding type defined by the field definitions on the model. (That is to say, they will be "demongoized".)

For example:

result = Person.raw.first
p result  #=> {"_id"=>BSON::ObjectId(...), "name" => "...", "birth_date" => 2002-01-01 00:00:00 -0600, ... }

result = Person.raw(typed: true).first
p result  #=> {"_id"=>BSON::ObjectId(...), "name" => "...", "birth_date" => 2002-01-01, ... }

results = Person.where(...).limit(...).raw
p results.to_a #=> [ { "_id"=>BSON::ObjectId(...), ... }, { "_id"=>BSON::ObjectId(...), ... }, ... ]

The typed: true option will also honor embedded documents, correctly demongoizing the embedded hashes according to their declared types.

MONGOID-5752 Add Mongoid::Criteria#to_mql (PR)

To help with inspecting the queries that Mongoid generates, you can now call #to_mql on Criteria instances.

Person.where(...).to_mql

MONGOID-5827 Allow duplicate indexes to be declared (PR)

Mongoid will ignore indexes that differ only in the options used to declare them. This includes index names! This behavior will change in the future, but to ease the transition, you can set Mongoid.allow_duplicate_index_declarations = true to allow these near-identical indexes to be declared and processed by the server.

MONGOID-5882 Isolation state (PR)

Some applications will use threads for concurrency. Others will use fibers. Prior to this PR, Mongoid worked fine with threads, but it's internal state could get into odd states when run under fibers.

This PR allows applications to indicate which isolation level they wish to use, and Mongoid's state will be isolated to that scope.

# the default -- inherit the isolation level from `ActiveSupport::IsolatedExecutionState` if possible
Mongoid.isolation_level = :rails

# The following two explicit settings are supported:
Mongoid.isolation_level = :thread # the classic behavior
Mongoid.isolation_level = :fiber  # NEW!

When using the :fiber isolation level, Mongoid's internal state will be inherited from any parent fiber. If you want to make sure a fiber begins with a clean slate, you can wipe the isolation state with Mongoid::Threaded.reset!.

MONGOID-5892 - Treat serialize option only with values of nil and [] differently (PR)

Previously, passing only: [] to serializable_hash was treated the same as passing only: nil, meaning all fields were included. The correct behavior is to treat an empty array as "include no fields," suppressing all output.

This fix is gated behind the Mongoid.serializable_hash_with_legacy_only feature flag. In 9.1 and later, the flag defaults to true (legacy behavior); set it to false to opt into the new behavior. The default will flip to false in Mongoid 10.0, and the flag will be removed in 11.0.

MONGOID-5910 Implement enumerable methods on top level models (any?, many?, and one?) (PR)

You may now invoke the enumerable methods #any?, #many?, and #one? on Criteria instances. Invoking them at the class level will delegate to those methods, as well.

User.any? #-> returns true if any (1 or more) user records exist
User.where(admin: true).one? #-> returns true if there is exactly one admin record
User.where(banned: true).many? #-> returns true if there are "many" (2 or more) banned users

MONGOID-5731 Add Criteria#eager_load method to use aggregation pipeline for eager loading (PR)

A new Criteria method, #eager_load, has been added. It is effectively the same as using #includes (joining associations into a single result), but it uses an aggregation pipeline under the covers to issue a single query, instead of the multiple queries that #includes may emit. The #eager_load method will typically perform better on has_many and has_and_belongs_to_many associations, and on queries where you are joining on multiple belongs_to or has_one associations.

people = Person.eager_load(children: %i[ hobbies favorites ], :employer, :partner)

If you use #eager_load to attempt to join on an embedded association (embeds_one, embeds_many), it will silently fall back to using #includes.

MONGOID-5930 Add Mongoid::Config.allow_reparenting_via_nested_attributes (PR)

Add Mongoid::Config.allow_reparenting_via_nested_attributes, defaulting to false. When false, this prevents dependent has_many records from being reparented via use of nested attributes. When true, records may be reparented via nested attributes.

This setting will be removed in Mongoid 10, and reparenting via nested attributes will not be allowed.

MONGOID-5898 Add vector search support (PR)

Mongoid can now define vector search indexes, and provides a helper interface for querying documents by their semantic meaning using those indexed vector fields.

The simplest interface will define an Array field, and a corresponding vector search index:

class Article
  include Mongoid::Document
  
  # Define `embedding` as an Array field, and define a vector search index on it
  # with `dimensions` set to 1536.
  vector_field :embedding, dimensions: 1536
end

For more sophisticated configurations, you may also declare the field and the index separately:

class Article
  include Mongoid::Document

  field :embedding, type: Array
  vector_search_index :embedding_index,
    fields: [
      { type: 'vector',
        path: 'embedding',
        dimensions: 1536,
        ...
      }
    ]
end

Then, create the new search indexes:

$ rake db:mongoid:create_search_indexes

Once the indexes are created, you can query them using the vector_search method:

articles = Article.vector_search(vector, limit: 5)

# or, search for documents that are similar to an existing document
neighbors = article.vector_search(limit: 5)

MONGOID-5923 Support auto emdedding vector search indexes and searches (PR)

Mongoid can now define vector search indexes with auto-embedding, and provides a helper interface for querying documents by their semantic meaning using those indexed vector fields.

The simplest interface will define a String field using the voyage-4 model.

class Article
  include Mongoid::Document
  
  # Define `body` as a String field, indexed using the `voyage-4` auto-embedding model.
  auto_embed_field :body
end

You may declare the model and other parameters as well, if desired:

class Article
  include Mongoid::Document

  auto_embed_field :body,
                       model: 'voyage-4-large'
                       num_dimensions: 512,
                       quantization: 'binary',
                       similarity: 'cosine',
                       index: :body_index
end

Then, create the new search indexes:

$ rake db:mongoid:create_search_indexes

Once the indexes are created, you can query them using the auto_embed_search method:

articles = Article.auto_embed_search('machine learning', limit: 5)

# or, search for documents that are similar to an existing document
neighbors = article.auto_embed_search(limit: 5)

MONGOID-5750 Allow build_foo on embeds_one/has_one/etc. to specify the associated document's type (PR)

When using build_<association> on an embeds_one/has_one/belongs_to (etc.) association, you can now specify the type of the associated document. For example:

class Job
  include Mongoid::Document
  
  has_one :runner
end

class Runner
  include Mongoid::Document
...
Read more

9.0.11

Choose a tag to compare

@mongodb-dbx-release-bot mongodb-dbx-release-bot released this 27 Apr 22:01
651cdfc

The MongoDB Ruby team is pleased to announce version 9.0.11 of the mongoid gem - a Ruby ODM for MongoDB. This is a new patch release in the 9.0.x series of Mongoid.

Install this release using RubyGems via the command line as follows:

gem install -v 9.0.11 mongoid

Or simply add it to your Gemfile:

gem 'mongoid', '9.0.11'

Have any feedback? Click on through to MongoDB's JIRA and open a new ticket to let us know what's on your mind 🧠.

New Features

MONGOID-5930 Add Mongoid::Config.allow_reparenting_via_nested_attributes (PR)

Add Mongoid::Config.allow_reparenting_via_nested_attributes, defaulting to true. When false, this prevents dependent has_many records from being reparented via use of nested attributes. When true, records may be reparented via nested attributes.

This setting will default to false in Mongoid 9.1, and will be removed in Mongoid 10.

MONGOID-5751 avoid unnecessary autosaves of unchanged subtrees (PR)

The legacy behavior of associations with autosave: true resulted in all #save being invoked on all children of those associations, whether those children actually needed it or not. All corresponding after_save hooks were invoked as well, recursively, clear to the bottom of the autosave tree.

This PR adds an option to change this behavior, ensuring that subtrees are only autosaved if there are any changed documents in the subtree.

Mongoid.autosave_saves_unchanged_documents = true

The default is true, allowing the legacy behavior to prevail. If your program depends on this legacy behavior, you are encouraged to rewrite the affected code and set the value to false. The default value of this option will be false in Mongoid 9.1, and will go away in Mongoid 10. At that point the legacy autosave behavior will be removed.

Other New Features

9.0.10

Choose a tag to compare

@mongodb-dbx-release-bot mongodb-dbx-release-bot released this 26 Jan 23:07
0623af6

The MongoDB Ruby team is pleased to announce version 9.0.10 of the mongoid gem - a Ruby ODM for MongoDB. This is a new patch release in the 9.0.x series of Mongoid.

Install this release using RubyGems via the command line as follows:

gem install -v 9.0.10 mongoid

Or simply add it to your Gemfile:

gem 'mongoid', '9.0.10'

Have any feedback? Click on through to MongoDB's JIRA and open a new ticket to let us know what's on your mind 🧠.

New Features

  • MONGOID-5864 Include Rails framework version in client metadata on initial handshake (PR)

Bug Fixes

  • MONGOID-5899 Write conflict error when accessing embedded documents via [] operator after direct DB update (PR)
  • MONGOID-5919 Restrict Criteria.from_hash method (PR)

8.1.12

Choose a tag to compare

@mongodb-dbx-release-bot mongodb-dbx-release-bot released this 26 Jan 23:02
f7a0d35

The MongoDB Ruby team is pleased to announce version 8.1.12 of the mongoid gem - a Ruby ODM for MongoDB. This is a new patch release in the 8.1.x series of Mongoid.

Install this release using RubyGems via the command line as follows:

gem install -v 8.1.12 mongoid

Or simply add it to your Gemfile:

gem 'mongoid', '8.1.12'

Have any feedback? Click on through to MongoDB's JIRA and open a new ticket to let us know what's on your mind 🧠.

New Features

  • MONGOID-4889 Optimize batch assignment of embedded documents (backport to 8.1) (PR)
  • MONGOID-5864 Include Rails framework version in client metadata on initial handshake (PR)

Bug Fixes

8.0.12

Choose a tag to compare

@mongodb-dbx-release-bot mongodb-dbx-release-bot released this 26 Jan 22:56
afd2a37

The MongoDB Ruby team is pleased to announce version 8.0.12 of the mongoid gem - a Ruby ODM for MongoDB. This is a new patch release in the 8.0.x series of Mongoid.

Install this release using RubyGems via the command line as follows:

gem install -v 8.0.12 mongoid

Or simply add it to your Gemfile:

gem 'mongoid', '8.0.12'

Have any feedback? Click on through to MongoDB's JIRA and open a new ticket to let us know what's on your mind 🧠.

New Features

  • MONGOID-5864 Include Rails framework version in client metadata on initial handshake (PR)

Bug Fixes

7.6.1

Choose a tag to compare

@mongodb-dbx-release-bot mongodb-dbx-release-bot released this 26 Jan 22:52
00356d4

The MongoDB Ruby team is pleased to announce version 7.6.1 of the mongoid gem - a Ruby ODM for MongoDB. This is a new patch release in the 7.6.x series of Mongoid.

Install this release using RubyGems via the command line as follows:

gem install -v 7.6.1 mongoid

Or simply add it to your Gemfile:

gem 'mongoid', '7.6.1'

Have any feedback? Click on through to MongoDB's JIRA and open a new ticket to let us know what's on your mind 🧠.

New Features

  • MONGOID-5864 Include Rails framework version in client metadata on initial handshake (PR)

Bug Fixes

9.0.9

Choose a tag to compare

@mongodb-dbx-release-bot mongodb-dbx-release-bot released this 18 Dec 16:55
a300511

The MongoDB Ruby team is pleased to announce version 9.0.9 of the mongoid gem - a Ruby ODM for MongoDB. This is a new patch release in the 9.0.x series of Mongoid.

Install this release using RubyGems via the command line as follows:

gem install -v 9.0.9 mongoid

Or simply add it to your Gemfile:

gem 'mongoid', '9.0.9'

Have any feedback? Click on through to MongoDB's JIRA and open a new ticket to let us know what's on your mind 🧠.

Bug Fixes

7.6.0

Choose a tag to compare

@mongodb-dbx-release-bot mongodb-dbx-release-bot released this 10 Dec 15:19
b78c8f3

The MongoDB Ruby team is pleased to announce version 7.6.0 of the mongoid gem - a Ruby ODM for MongoDB. This is a new minor release in the 7.x series of Mongoid.

Install this release using RubyGems via the command line as follows:

gem install -v 7.6.0 mongoid

Or simply add it to your Gemfile:

gem 'mongoid', '7.6.0'

Have any feedback? Click on through to MongoDB's JIRA and open a new ticket to let us know what's on your mind 🧠.

New Features

  • 7.6.0 is now officially compatible with the actual version of the Mongo Ruby Driver (PR)

9.0.8

Choose a tag to compare

@mongodb-dbx-release-bot mongodb-dbx-release-bot released this 18 Sep 20:07
57a3fc4

The MongoDB Ruby team is pleased to announce version 9.0.8 of the mongoid gem - a Ruby ODM for MongoDB. This is a new patch release in the 9.0.x series of Mongoid.

Install this release using RubyGems via the command line as follows:

gem install -v 9.0.8 mongoid

Or simply add it to your Gemfile:

gem 'mongoid', '9.0.8'

Have any feedback? Click on through to MongoDB's JIRA and open a new ticket to let us know what's on your mind 🧠.

Bug Fixes

  • MONGOID-5852 Fix after_action_commit callbacks (PR)
  • MONGOID-4889 Optimize batch assignment of embedded documents (PR)
  • MONGOID-5888 Ensure deeply nested children are validated correctly (PR)
  • MONGOID-5885 Return value from transaction yield to caller instead of internal state (PR)
  • MONGOID-5895 Make Reload Properly Update new_record (PR)
  • MONGOID-5887 Include server hint for aggregate operations (PR)
  • MONGOID-5869 Fix incorrectly named global_executor_concurrency config in code comment (PR)

9.0.7

Choose a tag to compare

@mongodb-dbx-release-bot mongodb-dbx-release-bot released this 24 Jul 16:36
50a3b72

The MongoDB Ruby team is pleased to announce version 9.0.7 of the mongoid gem - a Ruby ODM for MongoDB. This is a new patch release in the 9.0.x series of Mongoid.

Install this release using RubyGems via the command line as follows:

gem install -v 9.0.7 mongoid

Or simply add it to your Gemfile:

gem 'mongoid', '9.0.7'

Have any feedback? Click on through to MongoDB's JIRA and open a new ticket to let us know what's on your mind 🧠.

Bug Fixes

MONGOID-5848 Revert MONGOID-5822 (PR)

MONGOID-5822 attempted to fix a regression where child callbacks that depended on parent state were no longer invoked if the child had not changed. However, the fix itself introduced an unacceptable performance regression.

This PR restores the earlier functionality, which will break apps that depend on callbacks being invoked on unmodified children (for example, when a child callback depends simply on the parent having changed state).

For now, the correct way to implement that behavior is to explicitly iterate over the children in a parent callback, e.g.:

class Parent
  include Mongoid::Document
  has_many :children
  after_save { children.each(&:parent_changed_callback) }
end

class Child
  include Mongoid::Document
  belongs_to :parent
  
  def parent_changed_callback
    # ...
  end
end

Other Bug Fixes