Docs Menu

Docs HomeMongoid

Mongoid 7.0

On this page

  • set Overwrites Complete Document

This page describes significant changes and improvements in Mongoid 7.0. The complete list of releases is available on GitHub and in JIRA; please consult GitHub releases for detailed release notes and JIRA for the complete list of issues fixed in each release, including bug fixes.

Please note that improvements that have been backported to Mongoid 6.x are not included in this list.

The behavior of read-only attributes now matches that of ActiveRecord.

Referenced associations now support all dependent behaviors that ActiveRecord supports.

$unwind operator support added to the aggregation pipeline builder DSL.

background_indexing Mongoid configuration option added.

Mongoid 7.0 requires MongoDB server 2.6 or newer, Ruby 2.2.2 or higher and supports Rails 5.1-6.0.

New in version 7.0.3: Embedded matchers now support the $eq operator.

New in version 7.0.5: Mongoid now officially supports Rails 6.0.

Breaking change: In Mongoid 7.0.2 and higher, set fully overwrites the targeted attributes in the database, including any nested documents and nested attributes. This behavior matches that of MongoDB $set operator. In Mongoid 7.0.1 and lower, set retained other attributes present in the database below the document being written:

class Product
include Mongoid::Document
field :tags, type: Hash
product = {color: 'black'})
product.set(tags: {size: 'large'})
# Mongoid 7.0.2+:
# => #<Product _id: 62ab9770ce4ef31ac572679c, tags: {:size=>"large"}>
# Mongoid 7.0.1:
# => #<Product _id: 62ab9770ce4ef31ac572679c, tags: {:color=>"black", :size=>"large"}>
←  Mongoid 7.1Mongoid 6 →
Share Feedback
© 2023 MongoDB, Inc.


  • Careers
  • Investor Relations
  • Legal Notices
  • Privacy Notices
  • Security Information
  • Trust Center
© 2023 MongoDB, Inc.