diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md new file mode 100644 index 000000000..477f3506b --- /dev/null +++ b/CODE_OF_CONDUCT.md @@ -0,0 +1,15 @@ +# Conduct of Code + +1. "I fight for the Users." - Tron + +2. "Talk is cheap. Show me the code." - Linus Torvalds + +3. "Everything should be made as simple as possible, but not simpler." - Albert Einstein + +4. "The most dangerous phrase in the language is: We've always done it this way." - Grace Hopper + +5. "A feeling of aversion or attachment toward something is your clue that there's work to be done." - Ram Dass + +6. "I'm smart enough to know that I'm dumb." - Richard Feynman + +7. "Be excellent to each other." - Abraham Lincoln diff --git a/docs/index.txt b/docs/index.txt index 76660e556..e7fed377a 100644 --- a/docs/index.txt +++ b/docs/index.txt @@ -21,6 +21,3 @@ for MongoDB in Ruby. contributing additional-resources ecosystem - - -For documentation on Mongoid 3 and 4, see ``_. diff --git a/docs/installation.txt b/docs/installation.txt index 7247273d6..44ffdaba6 100644 --- a/docs/installation.txt +++ b/docs/installation.txt @@ -34,7 +34,7 @@ Using Mongoid with a New Rails Application When creating a new Rails application and wish to use Mongoid for data access, give the ``--skip-active-record`` flag to the ``rails new`` -command to avoid depending on and configuring ActiveRecord.. +command to avoid depending on and configuring ActiveRecord. Using Mongoid with an Existing Rails Application ================================================ diff --git a/docs/reference/compatibility.txt b/docs/reference/compatibility.txt index 7f616c315..79299b23e 100644 --- a/docs/reference/compatibility.txt +++ b/docs/reference/compatibility.txt @@ -34,52 +34,17 @@ specified Mongoid versions. - Driver 2.17-2.10 - Driver 2.9-2.7 - * - 9.0 + * - 8.0 thru 9.0 - |checkmark| - - - * - 8.1 + * - 7.2 thru 7.5 - |checkmark| - - - - - - * - 8.0 - |checkmark| - - - - * - 7.5 - - |checkmark| - - |checkmark| - - - - * - 7.4 - - |checkmark| - - |checkmark| - - - - * - 7.3 - - |checkmark| - - |checkmark| - - - - * - 7.2 - - |checkmark| - - |checkmark| - - - - * - 7.1 - - |checkmark| - - |checkmark| - - |checkmark| - - * - 7.0 - - |checkmark| - - |checkmark| - - |checkmark| - - * - 6.4 + * - 7.0 thru 7.1 - |checkmark| - |checkmark| - |checkmark| @@ -107,9 +72,9 @@ is deprecated. - Ruby 2.4 - Ruby 2.3 - Ruby 2.2 - - JRuby 9.2 - - JRuby 9.3 - JRuby 9.4 + - JRuby 9.3 + - JRuby 9.2 * - 9.0 - |checkmark| @@ -121,9 +86,9 @@ is deprecated. - - - + - |checkmark| - - - - |checkmark| * - 8.1 - |checkmark| @@ -139,7 +104,6 @@ is deprecated. - |checkmark| - - * - 8.0 - - |checkmark| @@ -164,9 +128,9 @@ is deprecated. - - - - - D - - |checkmark| - + - |checkmark| + - D * - 7.4 - @@ -178,9 +142,9 @@ is deprecated. - - - - - |checkmark| - - + - |checkmark| * - 7.3 - @@ -192,9 +156,9 @@ is deprecated. - D - D - - - |checkmark| - - + - |checkmark| * - 7.2 - @@ -206,9 +170,9 @@ is deprecated. - D - D - - - |checkmark| - - + - |checkmark| * - 7.1 - @@ -220,9 +184,9 @@ is deprecated. - |checkmark| [#ruby-2.4]_ - |checkmark| - - - |checkmark| - - + - |checkmark| * - 7.0 - @@ -234,23 +198,9 @@ is deprecated. - |checkmark| [#ruby-2.4]_ - |checkmark| - |checkmark| [#ruby-2.2]_ - - |checkmark| - - - - - - * - 6.4 - - - - - - - |checkmark| - - |checkmark| - - |checkmark| [#ruby-2.4]_ - - |checkmark| - - |checkmark| [#ruby-2.2]_ - - |checkmark| - - - - .. [#mongoid-7.3-ruby-3.0] Mongoid version 7.3.2 or higher is required. @@ -296,33 +246,7 @@ and will be removed in a next version. - MongoDB 3.0 - MongoDB 2.6 - * - 9.0 - - |checkmark| - - |checkmark| - - |checkmark| - - |checkmark| - - |checkmark| - - |checkmark| - - |checkmark| - - - - - - - - - - * - 8.1 - - |checkmark| - - |checkmark| - - |checkmark| - - |checkmark| - - |checkmark| - - |checkmark| - - |checkmark| - - - - - - - - - - * - 8.0 + * - 8.0 thru 9.0 - |checkmark| - |checkmark| - |checkmark| @@ -335,7 +259,7 @@ and will be removed in a next version. - - - * - 7.5 + * - 7.4 thru 7.5 - |checkmark| - |checkmark| - |checkmark| @@ -348,72 +272,7 @@ and will be removed in a next version. - D - D - * - 7.4 - - |checkmark| - - |checkmark| - - |checkmark| - - |checkmark| - - |checkmark| - - |checkmark| - - |checkmark| - - D - - D - - D - - D - - * - 7.3 - - - - - - |checkmark| - - |checkmark| - - |checkmark| - - |checkmark| - - |checkmark| - - D - - D - - D - - D - - * - 7.2 - - - - - - |checkmark| - - |checkmark| - - |checkmark| - - |checkmark| - - |checkmark| - - D - - D - - D - - D - - * - 7.1 - - - - - - |checkmark| - - |checkmark| - - |checkmark| - - |checkmark| - - |checkmark| - - D - - D - - D - - D - - * - 7.0 - - - - - - |checkmark| - - |checkmark| - - |checkmark| - - |checkmark| - - |checkmark| - - D - - D - - D - - D - - * - 6.4 + * - 7.0 thru 7.3 - - - |checkmark| @@ -456,15 +315,7 @@ are supported by Mongoid. - - - * - 8.1 - - |checkmark| [#rails-7.1]_ - - |checkmark| - - |checkmark| - - |checkmark| - - |checkmark| [#rails-5-ruby-3.0]_ - - - - * - 8.0 + * - 8.0 thru 8.1 - |checkmark| [#rails-7.1]_ - |checkmark| - |checkmark| @@ -520,14 +371,6 @@ are supported by Mongoid. - |checkmark| - |checkmark| - * - 6.4 - - - - - - - - - - |checkmark| - - |checkmark| - .. [#rails-5-ruby-3.0] Using Rails 5.x with Ruby 3 is not supported. .. [#rails-6] Rails 6.0 requires Mongoid 7.0.5 or later. diff --git a/docs/reference/configuration.txt b/docs/reference/configuration.txt index 0014cb452..852f32194 100644 --- a/docs/reference/configuration.txt +++ b/docs/reference/configuration.txt @@ -396,7 +396,7 @@ for details on driver options. driver_options: # When this flag is off, an aggregation done on a view will be executed over # the documents included in that view, instead of all documents in the - # collection. When this flag is on, the view fiter is ignored. + # collection. When this flag is on, the view filter is ignored. # broken_view_aggregate: true # When this flag is set to false, the view options will be correctly @@ -404,7 +404,7 @@ for details on driver options. # broken_view_options: true # When this flag is set to true, the update and replace methods will - # validate the paramters and raise an error if they are invalid. + # validate the parameters and raise an error if they are invalid. # validate_update_replace: false @@ -541,9 +541,8 @@ Place the following in one of environment configuration files, such as .. note:: - The ``log_level`` Mongoid `configuration option `_ - is not used when Mongoid operates in a Rails application, because Mongoid - inherits Rails' log level in this case. + The ``log_level`` Mongoid configuration option is not used when Mongoid operates + in a Rails application, because Mongoid inherits Rails' log level in this case. To configure either Mongoid or driver logger differently from the Rails logger, use an initializer as follows: @@ -590,8 +589,8 @@ Standalone ---------- When not loaded in a Ruby on Rails application, Mongoid respects the -``log_level`` top level `configuration option `_. -It can be given in the configuration file as follows: +``log_level`` top level configuration option. It can be given in the +configuration file as follows: .. code-block:: yaml @@ -746,11 +745,11 @@ It may be desirable to further configure TLS options in your application, for example by enabling or disabling certain ciphers. This can be done by setting TLS context hooks on the Ruby driver -- TLS context -hooks are user-provided ``Proc``s that will be invoked before any TLS socket +hooks are user-provided ``Proc``\(s) that will be invoked before any TLS socket connection in the driver and can be used to modify the underlying ``OpenSSL::SSL::SSLContext`` object used by the socket. -To set TLS context hooks, add ``Proc``s to the ``Mongo.tls_context_hooks`` +To set TLS context hooks, add ``Proc``\(s) to the ``Mongo.tls_context_hooks`` array. This can be done in an initializer. The example below adds a hook that only enables the "AES256-SHA" cipher. @@ -830,7 +829,7 @@ Client-Side Encryption When loading the configuration file, Mongoid permits the file to contain ``BSON::Binary`` instances which are used for specifying ``keyId`` in the schema map for `client-side encryption -`_, +`_, as the following example shows: .. code-block:: yaml diff --git a/docs/reference/fields.txt b/docs/reference/fields.txt index 6687a6a42..5e29bfeec 100644 --- a/docs/reference/fields.txt +++ b/docs/reference/fields.txt @@ -927,7 +927,7 @@ Reading Uncastable Values ````````````````````````` When documents in the database contain values of different types than their -represenations in Mongoid, if Mongoid cannot coerce them into the correct type, +representations in Mongoid, if Mongoid cannot coerce them into the correct type, it will replace the value with ``nil``. Consider the following model and document in the database: @@ -1105,7 +1105,7 @@ used for MongoDB serialization and deserialization as follows: end The instance method ``mongoize`` takes an instance of your custom type object, and -converts it into a represenation of how it will be stored in the database, i.e. to pass +converts it into a representation of how it will be stored in the database, i.e. to pass to the MongoDB Ruby driver. In our example above, we want to store our ``Point`` object as an ``Array`` in the form ``[ x, y ]``. @@ -1228,7 +1228,7 @@ which extend its behavior at the your time model classes are loaded. As an example, we will define a ``:max_length`` option which will add a length validator for the field. First, declare the new field option in an initializer, -specifiying its handler function as a block: +specifying its handler function as a block: .. code-block:: ruby diff --git a/docs/reference/queries.txt b/docs/reference/queries.txt index 79ecd9cc9..8dcae9b27 100644 --- a/docs/reference/queries.txt +++ b/docs/reference/queries.txt @@ -1154,7 +1154,7 @@ examples. If any of the ``_id`` values are not found in the database, the behavior of ``find`` depends on the value of the ``raise_not_found_error`` configuration option. If the option is set to ``true``, ``find`` raises -``Mongoid::Errors::DocumentNotFound`` if any of the ``_id``s are not found. +``Mongoid::Errors::DocumentNotFound`` if any of the ``_id``\s are not found. If the option is set to ``false`` and ``find`` is given a single ``_id`` to find and there is no matching document, ``find`` returns ``nil``. If the option is set to ``false`` and ``find`` is given an array of ids to find diff --git a/docs/reference/rails-integration.txt b/docs/reference/rails-integration.txt index 4c7181cff..2f8f02ace 100644 --- a/docs/reference/rails-integration.txt +++ b/docs/reference/rails-integration.txt @@ -24,7 +24,7 @@ other Rails environment specific options by accessing config.mongoid. The ``mongoid:config`` generator will create an initializer in ``config/initializers/mongoid.rb`` which can also be used for configuring Mongoid. Note, though, that options set in your ``config/mongoid.yml`` will -take precendence over options set elsewhere; it is recommended that whenever +take precedence over options set elsewhere; it is recommended that whenever possible you use ``mongoid.yml`` as the default location for Mongoid configuration. diff --git a/docs/reference/sharding.txt b/docs/reference/sharding.txt index ab451bf4a..675e62cae 100644 --- a/docs/reference/sharding.txt +++ b/docs/reference/sharding.txt @@ -35,8 +35,8 @@ Shard keys can be declared on models using the ``shard_key`` macro: end Note that in order to shard a collection, the collection must have an index -that starts with the shard key. Mongoid provides `index management -`_ functionality, which the examples here take +that starts with the shard key. Mongoid provides :ref:`index management +` functionality, which the examples here take advantage of. Mongoid supports two syntaxes for declaring shard keys. The standard syntax diff --git a/docs/reference/text-search.txt b/docs/reference/text-search.txt index c962b3667..b7c3013de 100644 --- a/docs/reference/text-search.txt +++ b/docs/reference/text-search.txt @@ -35,8 +35,8 @@ To perform text search with Mongoid, follow these steps: Defining Text Search Index -------------------------- -Index definition through Mongoid is described in detail on the `indexes -`_ page. Text search indexes are described in detail +Index definition through Mongoid is described in detail on the :ref:`indexes +` page. Text search indexes are described in detail under `text indexes `_ in the MongoDB manual. Below is an example definition of a Band model with a text index utilizing the description field: diff --git a/docs/release-notes/mongoid-8.0.txt b/docs/release-notes/mongoid-8.0.txt index 69e17c6d9..b0d93132c 100644 --- a/docs/release-notes/mongoid-8.0.txt +++ b/docs/release-notes/mongoid-8.0.txt @@ -84,59 +84,69 @@ evolve an uncastable value, the inputted value is returned. See the section on Some ``mongoize``, ``demongoize`` and ``evolve`` methods were also changed to perform consistently with rails and the other ``mongoize``, ``demongoize`` and -``evolve`` methods. The following is a table of the changes in functionality: - -+--------------+------------------------+------------------------+-----------------------+ -| Field Type | Situation | Previous Functionality | New Functionality | -+==============+========================+========================+=======================+ -| Boolean | When a non-boolean | return ``false`` | return ``nil`` | -| | string is assigned: | | | -| | "bogus value" | | | -+--------------+------------------------+------------------------+-----------------------+ -| Array/Hash | When a value that is | raise ``InvalidValue`` | return ``nil`` | -| | not an array or hash | error | | -| | is assigned | | | -+--------------+------------------------+------------------------+-----------------------+ -| Set | When a value that is | raise ``NoMethodError``| return ``nil`` | -| | not a set is assigned: | Exception: undefined | | -| | 1 | method ``to_a`` for | | -| | | 1:Integer | | -+--------------+------------------------+------------------------+-----------------------+ -| Regexp | When persisting and | return a | return a | -| | reading a Regexp from | ``BSON::Regexp::Raw`` | ``Regexp`` | -| | the database | | | -+--------------+------------------------+------------------------+-----------------------+ -| Time/DateTime| When assigning a | raise ``NoMethodError``| return ``nil`` | -| | bogus value: ``:bogus``| Exception: undefined | | -| | | method ``to_i`` | | -| | | for :bogus:Symbol | | -+--------------+------------------------+------------------------+-----------------------+ -| Time/DateTime| When demongoizing a | raise ``NoMethodError``| "bogus": | -| | non-Time value: | Exception: undefined | return ``nil`` | -| | "bogus", | method ``getlocal`` | | -| | ``Date.today`` | for "bogus":String | ``Date.today``: | -| | | | return a | -| | | | ``Time/DateTime`` | -+--------------+------------------------+------------------------+-----------------------+ -| Date | When assigning or | raise ``NoMethodError``| return ``nil`` | -| | demongoizing a bogus | Exception: undefined | | -| | value: :bogus | method ``year`` | | -| | | for :bogus:Symbol | | -+--------------+------------------------+------------------------+-----------------------+ -| Time/DateTime| When demongoizing a | raise ``NoMethodError``| return a | -| /Date | valid string: | Exception: undefined | ``Time/DateTime/Date``| -| | "2022-07-14 14:45:51 | method ``getlocal`` | | -| | -0400" | for "2022-07-14 | | -| | | 14:45:51 -0400":String | | -+--------------+------------------------+------------------------+-----------------------+ -| All Types | When an uncastable | undefined behavior, | return ``nil`` | -| | value is assigned or | occasionally raise | | -| | demongoized | ``NoMethodError`` | | -+--------------+------------------------+------------------------+-----------------------+ -| All Types | When an uncastable | undefined behavior, | return inputted value | -| | value is evolved | occasionally raise | | -| | | ``NoMethodError`` | | -+--------------+------------------------+------------------------+-----------------------+ +``evolve`` methods. The following table shows the changes in functionality: + +.. list-table:: + :widths: 1 2 2 2 + :stub-columns: 1 + :header-rows: 1 + + * - Field Type + - Situation + - Previous Functionality + - New Functionality + + * - | Boolean + - | When a non-boolean string is assigned: "bogus value" + - | return ``false`` + - | return ``nil`` + + * - Array/Hash + - When a value that is not an array or hash is assigned + - raise ``InvalidValue`` error + - return ``nil`` + + * - | Set + - | When a value that is not a set is assigned: 1 + - | raise ``NoMethodError`` Exception: undefined method ``to_a`` for 1:Integer + - | return ``nil`` + + * - Regexp + - When persisting and reading a Regexp from the database + - return a ``BSON::Regexp::Raw`` + - return a ``Regexp`` + + * - | Time/DateTime + - | When assigning a bogus value: ``:bogus`` + - | raise ``NoMethodError`` Exception: undefined method ``to_i`` for :bogus:Symbol + - | return ``nil`` + + * - Time/DateTime + - When demongoizing a non-Time value: "bogus", ``Date.today`` + - raise ``NoMethodError`` Exception: undefined method ``getlocal`` for "bogus":String + - "bogus": return ``nil`` + + ``Date.today``: return ``Time/DateTime`` + + * - | Date + - | When assigning or demongoizing a bogus value: :bogus + - | raise ``NoMethodError`` Exception: undefined method ``year`` for :bogus:Symbol + - | return ``nil`` + + * - Time/DateTime/Date + - When demongoizing a valid string: "2022-07-14 14:45:51 -0400" + - raise ``NoMethodError`` Exception: undefined method ``getlocal`` for "2022-07-14 14:45:51 -0400":String + - return a ``Time/DateTime/Date`` + + * - | All Types + - | When an uncastable value is assigned or demongoized + - | undefined behavior, occasionally raise ``NoMethodError`` + - | return ``nil`` + + * - All Types + - When an uncastable value is evolved + - undefined behavior, occasionally raise ``NoMethodError`` + - return inputted value .. note:: @@ -145,7 +155,6 @@ perform consistently with rails and the other ``mongoize``, ``demongoize`` and https://jira.mongodb.org/browse/MONGOID-2951 for a longer discussion on these bugs. - Changes to the ``attributes_before_type_cast`` Hash --------------------------------------------------- @@ -177,98 +186,144 @@ invocation for documents with associations. Referenced associations (``has_one`` and ``has_many``): -+---------------------------------------+---------------------------------------+ -| Mongoid 8.0 | Mongoid 7 | -+=======================================+=======================================+ -| Parent :before_save | Parent :before_save | -+---------------------------------------+---------------------------------------+ -| Parent :around_save_open | Parent :around_save_open | -+---------------------------------------+---------------------------------------+ -| Parent :before_create | Parent :before_create | -+---------------------------------------+---------------------------------------+ -| Parent :around_create_open | Parent :around_create_open | -+---------------------------------------+---------------------------------------+ -| **Parent persisted in MongoDB** | **Parent persisted in MongoDB** | -+---------------------------------------+---------------------------------------+ -| Child :before_save | Parent :around_create_close | -+---------------------------------------+---------------------------------------+ -| Child :around_save_open | Parent :after_create | -+---------------------------------------+---------------------------------------+ -| Child :before_create | Child :before_save | -+---------------------------------------+---------------------------------------+ -| Child :around_create_open | Child :around_save_open | -+---------------------------------------+---------------------------------------+ -| | Child :before_create | -+---------------------------------------+---------------------------------------+ -| | Child :around_create_open | -+---------------------------------------+---------------------------------------+ -| **Child persisted in MongoDB** | **Child persisted in MongoDB** | -+---------------------------------------+---------------------------------------+ -| Child :around_create_close | Child :around_create_close | -+---------------------------------------+---------------------------------------+ -| Child :after_create | Child :after_create | -+---------------------------------------+---------------------------------------+ -| Child :around_save_close | Child :around_save_close | -+---------------------------------------+---------------------------------------+ -| Child :after_save | Child :after_save | -+---------------------------------------+---------------------------------------+ -| Parent :around_create_close | Parent :around_save_close | -+---------------------------------------+---------------------------------------+ -| Parent :after_create | Parent :after_save | -+---------------------------------------+---------------------------------------+ -| Parent :around_save_close | | -+---------------------------------------+---------------------------------------+ -| Parent :after_save | | -+---------------------------------------+---------------------------------------+ +.. list-table:: + :header-rows: 1 + :widths: 50 50 + + * - Mongoid 8.0 + - Mongoid 7 + + * - | Parent :before_save + - | Parent :before_save + + * - Parent :around_save_open + - Parent :around_save_open + + * - | Parent :before_create + - | Parent :before_create + + * - Parent :around_create_open + - Parent :around_create_open + + * - | **Parent persisted in MongoDB** + - | **Parent persisted in MongoDB** + + * - Child :before_save + - Parent :around_create_close + + * - | Child :around_save_open + - | Parent :after_create + + * - Child :before_create + - Child :before_save + + * - | Child :around_create_open + - | Child :around_save_open + + * - + - Child :before_create + + * - | + - | Child :around_create_open + + * - **Child persisted in MongoDB** + - **Child persisted in MongoDB** + + * - | Child :around_create_close + - | Child :around_create_close + + * - Child :after_create + - Child :after_create + + * - | Child :around_save_close + - | Child :around_save_close + + * - Child :after_save + - Child :after_save + + * - | Parent :around_create_close + - | Parent :around_save_close + + * - Parent :after_create + - Parent :after_save + + * - | Parent :around_save_close + - | + + * - Parent :after_save + - Embedded associations (``embeds_one`` and ``embeds_many``): -+---------------------------------------+---------------------------------------+ -| Mongoid 8.0 | Mongoid 7 | -+=======================================+=======================================+ -| Parent :before_save | Child :before_save | -+---------------------------------------+---------------------------------------+ -| Parent :around_save_open | Child :around_save_open | -+---------------------------------------+---------------------------------------+ -| Parent :before_create | Child :around_save_close | -+---------------------------------------+---------------------------------------+ -| Parent :around_create_open | Child :after_save | -+---------------------------------------+---------------------------------------+ -| Child :before_save | Parent :before_save | -+---------------------------------------+---------------------------------------+ -| Child :around_save_open | Parent :around_save_open | -+---------------------------------------+---------------------------------------+ -| Child :before_create | Child :before_create | -+---------------------------------------+---------------------------------------+ -| Child :around_create_open | Child :around_create_open | -+---------------------------------------+---------------------------------------+ -| | Child :around_create_close | -+---------------------------------------+---------------------------------------+ -| | Child :after_create | -+---------------------------------------+---------------------------------------+ -| | Parent :before_create | -+---------------------------------------+---------------------------------------+ -| | Parent :around_create_open | -+---------------------------------------+---------------------------------------+ -| **Document persisted in MongoDB** | **Document persisted in MongoDB** | -+---------------------------------------+---------------------------------------+ -| Child :around_create_close | | -+---------------------------------------+---------------------------------------+ -| Child :after_create | | -+---------------------------------------+---------------------------------------+ -| Child :around_save_close | | -+---------------------------------------+---------------------------------------+ -| Child :after_save | | -+---------------------------------------+---------------------------------------+ -| Parent :around_create_close | Parent :around_create_close | -+---------------------------------------+---------------------------------------+ -| Parent :after_create | Parent :after_create | -+---------------------------------------+---------------------------------------+ -| Parent :around_save_close | Parent :around_save_close | -+---------------------------------------+---------------------------------------+ -| Parent :after_save | Parent :after_save | -+---------------------------------------+---------------------------------------+ +.. list-table:: + :header-rows: 1 + :widths: 50 50 + + * - Mongoid 8.0 + - Mongoid 7 + + * - | Parent :before_save + - | Child :before_save + + * - Parent :around_save_open + - Child :around_save_open + + * - | Parent :before_create + - | Child :around_save_close + + * - Parent :around_create_open + - Child :after_save + + * - | Child :before_save + - | Parent :before_save + + * - Child :around_save_open + - Parent :around_save_open + + * - | Child :before_create + - | Child :before_create + + * - Child :around_create_open + - Child :around_create_open + + * - | + - | Child :around_create_close + + * - + - Child :after_create + + * - | + - | Parent :before_create + + * - + - Parent :around_create_open + + * - | **Document persisted in MongoDB** + - | **Document persisted in MongoDB** + + * - Child :around_create_close + - + + * - | Child :after_create + - | + + * - Child :around_save_close + - + + * - | Child :after_save + - | + + * - Parent :around_create_close + - Parent :around_create_close + + * - | Parent :after_create + - | Parent :after_create + + * - Parent :around_save_close + - Parent :around_save_close + * - | Parent :after_save + - | Parent :after_save ``Changeable`` Module Behavior Made Compatible With ``ActiveModel::Dirty`` -------------------------------------------------------------------------- diff --git a/docs/release-notes/mongoid-9.0.txt b/docs/release-notes/mongoid-9.0.txt index 09fa47fb2..8a32c94a6 100644 --- a/docs/release-notes/mongoid-9.0.txt +++ b/docs/release-notes/mongoid-9.0.txt @@ -43,19 +43,6 @@ Consider using `MongoDB Atlas `_ to automate your MongoDB server upgrades. -Support for Ruby 2.6 and JRuby 9.3 Dropped -------------------------------------------- - -Mongoid 9 requires Ruby 2.7 or newer or JRuby 9.4. Earlier Ruby and JRuby -versions are not supported. - - -Support for Rails 5 Dropped ------------------------------ - -Mongoid 9 requires Rails 6.0 or newer. Earlier Rails versions are not supported. - - Deprecated class ``Mongoid::Errors::InvalidStorageParent`` removed ------------------------------------------------------------------ @@ -73,10 +60,11 @@ If you want to restore the old behavior, you can set ``Mongoid.around_embedded_document_callbacks`` to true in your application. .. note:: - Enabling ``around_*`` callbacks for embedded documents is not recommended - as it may cause ``SystemStackError`` exceptions when a document has many - embedded documents. See `MONGOID-5658 `_ - for more details. + + Enabling ``around_*`` callbacks for embedded documents is not recommended + as it may cause ``SystemStackError`` exceptions when a document has many + embedded documents. See `MONGOID-5658 `_ + for more details. ``for_js`` method is deprecated @@ -114,15 +102,16 @@ prior has been dropped (you must use a minimum of version 8.0.) Deprecated functionality removed -------------------------------- -The following previously deprecated functionality is now removed: +**Breaking change:** The following deprecated functionality is now removed: - The ``Mongoid::QueryCache`` module has been removed. Please replace any usages 1-for-1 with ``Mongo::QueryCache``. The method ``Mongoid::QueryCache#clear_cache`` should be replaced with ``Mongo::QueryCache#clear``. All other methods and submodules are identically named. Refer to the `driver query cache documentation `_ for more details. - ``Object#blank_criteria?`` method is removed (was previously deprecated.) -- ``Document#as_json :compact`` option is removed. Please call ```#compact`` - on the returned ``Hash`` object instead. +- ``Document#as_json :compact`` option is removed. Please call ```#compact`` on the + returned ``Hash`` object instead. +- The deprecated class ``Mongoid::Errors::InvalidStorageParent`` has been removed. - ``Criteria#geo_near`` is removed as MongoDB server versions 4.2 and later no longer support the ``$geoNear`` command. Please use the `$geoNear stage of the aggregation pipeline @@ -145,22 +134,22 @@ In Mongoid 8.x and older ``touch`` method leaves models in the changed state: .. code-block:: ruby - # Mongoid 8.x behaviour - band = Band.create! - band.touch - band.changed? # => true - band.changes # => {"updated_at"=>[2023-01-30 13:12:57.477191135 UTC, 2023-01-30 13:13:11.482975646 UTC]} + # Mongoid 8.x behaviour + band = Band.create! + band.touch + band.changed? # => true + band.changes # => {"updated_at"=>[2023-01-30 13:12:57.477191135 UTC, 2023-01-30 13:13:11.482975646 UTC]} Starting from 9.0 Mongoid now correctly clears changed state after using ``touch`` method. .. code-block:: ruby - # Mongoid 9.0 behaviour - band = Band.create! - band.touch - band.changed? # => false - band.changes # => {} + # Mongoid 9.0 behaviour + band = Band.create! + band.touch + band.changed? # => false + band.changes # => {} Sandbox Mode for Rails Console ------------------------------ @@ -172,8 +161,9 @@ the commands executed in the console using the ``:default`` client won't be persisted in the database. .. note:: - If you execute commands in the sandbox mode *using any other client than default*, - these changes will be persisted as usual. + + If you execute commands in the sandbox mode *using any other client than default*, + these changes will be persisted as usual. New Transactions API -------------------- @@ -182,15 +172,15 @@ Mongoid 9.0 introduces new transactions API that is inspired by ActiveRecord: .. code-block:: ruby - Band.transaction do - Band.create(title: 'Led Zeppelin') - end + Band.transaction do + Band.create(title: 'Led Zeppelin') + end - band = Band.create(title: 'Deep Purple') - band.transaction do - band.active = false - band.save! - end + band = Band.create(title: 'Deep Purple') + band.transaction do + band.active = false + band.save! + end Please consult :ref:`transactions documentation ` for more details. @@ -231,11 +221,11 @@ when the instance was loaded, Mongoid will now raise a .. code-block:: ruby - Band.only(:name).first.label - #=> raises Mongoid::Errors::AttributeNotLoaded + Band.only(:name).first.label + #=> raises Mongoid::Errors::AttributeNotLoaded - Band.without(:label).first.label = 'Sub Pop Records' - #=> raises Mongoid::Errors::AttributeNotLoaded + Band.without(:label).first.label = 'Sub Pop Records' + #=> raises Mongoid::Errors::AttributeNotLoaded In earlier Mongoid versions, the same conditions would raise an ``ActiveModel::MissingAttributeError``. Please check your code for @@ -253,17 +243,17 @@ considers ``Time.zone`` to perform type conversion. .. code-block:: ruby - class Magazine - include Mongoid::Document + class Magazine + include Mongoid::Document - field :published_at, type: Time - end + field :published_at, type: Time + end - Time.zone = 'Asia/Tokyo' + Time.zone = 'Asia/Tokyo' - Magazine.gte(published_at: Date.parse('2022-09-26')) - #=> will return all results on or after Sept 26th, 2022 - # at 0:00 in Asia/Tokyo time zone. + Magazine.gte(published_at: Date.parse('2022-09-26')) + #=> will return all results on or after Sept 26th, 2022 + # at 0:00 in Asia/Tokyo time zone. In prior Mongoid versions, the above code would ignore the ``Time.zone`` (irrespective of the now-removed ``:use_activesupport_time_zone`` @@ -282,25 +272,25 @@ invoke ``#touch`` on its parent document. .. code-block:: ruby - class Address - include Mongoid::Document - include Mongoid::Timestamps + class Address + include Mongoid::Document + include Mongoid::Timestamps - embedded_in :mall, touch: false - end + embedded_in :mall, touch: false + end - class Mall - include Mongoid::Document - include Mongoid::Timestamps + class Mall + include Mongoid::Document + include Mongoid::Timestamps - embeds_many :addresses - end + embeds_many :addresses + end - mall = Mall.create! - address = mall.addresses.create! + mall = Mall.create! + address = mall.addresses.create! - address.touch - #=> updates address.updated_at but not mall.updated_at + address.touch + #=> updates address.updated_at but not mall.updated_at In addition, the ``#touch`` method has been optimized to perform one persistence operation per parent document, even when using multiple @@ -315,12 +305,12 @@ unless you explicitly set ``touch: false`` on the relation: .. code-block:: ruby - class Address - include Mongoid::Document - include Mongoid::Timestamps + class Address + include Mongoid::Document + include Mongoid::Timestamps - embedded_in :mall, touch: false - end + embedded_in :mall, touch: false + end For all other associations, the default remains ``touch: false``. @@ -352,7 +342,7 @@ defaults to ``true``. .. code-block:: ruby - Mongoid::Config.immutable_ids = true + Mongoid::Config.immutable_ids = true When set to false, the older, inconsistent behavior is restored. @@ -395,18 +385,18 @@ of the ``index`` macro: ``partial_filter_expression``, ``weights``, .. code-block:: ruby - class Person - include Mongoid::Document - field :a, as: :age - index({ age: 1 }, { partial_filter_expression: { age: { '$gte' => 20 } }) - end + class Person + include Mongoid::Document + field :a, as: :age + index({ age: 1 }, { partial_filter_expression: { age: { '$gte' => 20 } }) + end .. note:: - The expansion of field name aliases in index options such as - ``partial_filter_expression`` is performed according to the behavior of MongoDB - server 6.0. Future server versions may change how they interpret these options, - and Mongoid's functionality may not support such changes. + The expansion of field name aliases in index options such as + ``partial_filter_expression`` is performed according to the behavior of MongoDB + server 6.0. Future server versions may change how they interpret these options, + and Mongoid's functionality may not support such changes. BSON 5 and BSON::Decimal128 Fields @@ -418,32 +408,32 @@ declared as BSON::Decimal128 will return a BigDecimal value by default. .. code-block:: ruby - class Model - include Mongoid::Document + class Model + include Mongoid::Document - field :decimal_field, type: BSON::Decimal128 - end + field :decimal_field, type: BSON::Decimal128 + end - # under BSON <= 4 - Model.first.decimal_field.class #=> BSON::Decimal128 + # under BSON <= 4 + Model.first.decimal_field.class #=> BSON::Decimal128 - # under BSON >= 5 - Model.first.decimal_field.class #=> BigDecimal + # under BSON >= 5 + Model.first.decimal_field.class #=> BigDecimal If you need literal BSON::Decimal128 values with BSON 5, you may instruct Mongoid to allow literal BSON::Decimal128 fields: .. code-block:: ruby - Model.first.decimal_field.class #=> BigDecimal + Model.first.decimal_field.class #=> BigDecimal - Mongoid.allow_bson5_decimal128 = true - Model.first.decimal_field.class #=> BSON::Decimal128 + Mongoid.allow_bson5_decimal128 = true + Model.first.decimal_field.class #=> BSON::Decimal128 .. note:: - The ``allow_bson5_decimal128`` option only has any effect under - BSON 5 and later. BSON 4 and earlier ignore the setting entirely. + The ``allow_bson5_decimal128`` option only has any effect under + BSON 5 and later. BSON 4 and earlier ignore the setting entirely. Search Index Management with MongoDB Atlas @@ -455,23 +445,23 @@ API: .. code-block:: ruby - class SearchablePerson - include Mongoid::Document + class SearchablePerson + include Mongoid::Document - search_index { ... } # define the search index here - end + search_index { ... } # define the search index here + end - # create the declared search indexes; this returns immediately, but the - # search indexes may take several minutes before they are available. - SearchablePerson.create_search_indexes + # create the declared search indexes; this returns immediately, but the + # search indexes may take several minutes before they are available. + SearchablePerson.create_search_indexes - # query the available search indexes - SearchablePerson.search_indexes.each do |index| - # ... - end + # query the available search indexes + SearchablePerson.search_indexes.each do |index| + # ... + end - # remove all search indexes from the model's collection - SearchablePerson.remove_search_indexes + # remove all search indexes from the model's collection + SearchablePerson.remove_search_indexes If you are not connected to MongoDB Atlas, the search index definitions are ignored. Trying to create, enumerate, or remove search indexes will result in @@ -481,16 +471,16 @@ There are also rake tasks available, for convenience: .. code-block:: bash - # create search indexes for all models; waits for indexes to be created - # and shows progress on the terminal. - $ rake mongoid:db:create_search_indexes + # create search indexes for all models; waits for indexes to be created + # and shows progress on the terminal. + $ rake mongoid:db:create_search_indexes - # as above, but returns immediately and lets the indexes be created in the - # background - $ rake WAIT_FOR_SEARCH_INDEXES=0 mongoid:db:create_search_indexes + # as above, but returns immediately and lets the indexes be created in the + # background + $ rake WAIT_FOR_SEARCH_INDEXES=0 mongoid:db:create_search_indexes - # removes search indexes from all models - $ rake mongoid:db:remove_search_indexes + # removes search indexes from all models + $ rake mongoid:db:remove_search_indexes ``Time.configured`` has been removed @@ -504,33 +494,33 @@ Mongoid now requires that you set a time zone if you intend to do anything with time values (including using timestamps in your documents). Any uses of ``Time.configured`` must be replaced with ``Time.zone``. -... code-block:: ruby +.. code-block:: ruby - # before: - puts Time.configured.now + # before: + puts Time.configured.now - # after: - puts Time.zone.now + # after: + puts Time.zone.now - # or, better for finding the current Time specifically: - puts Time.current + # or, better for finding the current Time specifically: + puts Time.current If you do not set a time zone, you will see errors in your code related to ``nil`` values. If you are using Rails, the default time zone is already set to UTC. If you are not using Rails, you may set a time zone at the start of your program like this: -... code-block:: ruby +.. code-block:: ruby - Time.zone = 'UTC' + Time.zone = 'UTC' This will set the time zone to UTC. You can see all available time zone names by running the following command: -... code-block:: bash +.. code-block:: bash - $ ruby -ractive_support/values/time_zone \ - -e 'puts ActiveSupport::TimeZone::MAPPING.keys' + $ ruby -ractive_support/values/time_zone \ + -e 'puts ActiveSupport::TimeZone::MAPPING.keys' Records now remember the persistence context in which they were loaded/created @@ -538,10 +528,10 @@ Records now remember the persistence context in which they were loaded/created Consider the following code: -... code-block:: ruby +.. code-block:: ruby - record = Model.with(collection: 'other_collection') { Model.first } - record.update(field: 'value') + record = Model.with(collection: 'other_collection') { Model.first } + record.update(field: 'value') Prior to Mongoid 9.0, this could would silently fail to execute the update, because the storage options (here, the specification of an alternate @@ -558,9 +548,9 @@ a different database, or a different collection). If you need the legacy (pre-9.0) behavior, you can enable it with the following flag: -... code-block:: ruby +.. code-block:: ruby - Mongoid.legacy_persistence_context_behavior = true + Mongoid.legacy_persistence_context_behavior = true This flag defaults to false in Mongoid 9. diff --git a/docs/release-notes/upgrading.txt b/docs/release-notes/upgrading.txt index 1ae90c1cf..db27af622 100644 --- a/docs/release-notes/upgrading.txt +++ b/docs/release-notes/upgrading.txt @@ -49,10 +49,10 @@ Before you Upgrade ------------------ - *Test Coverage:* The best way to be sure that your application still works after upgrading -is to have good test coverage before you start the process. + is to have good test coverage before you start the process. - *Upgrade Ruby and Rails:* See `"Upgrading Ruby on Rails" `_ -for more information + for more information Upgrading Mongoid diff --git a/docs/tutorials/automatic-encryption.txt b/docs/tutorials/automatic-encryption.txt index dd7ce2890..4da882595 100644 --- a/docs/tutorials/automatic-encryption.txt +++ b/docs/tutorials/automatic-encryption.txt @@ -64,9 +64,11 @@ This can be done one of two ways. Install the automatic encryption shared library (Ruby driver 2.19+) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -If you use the Ruby driver version 2.19 and above the automatic encryption -shared library should be installed by following the instructions in the -`MongoDB manual `_. +If you use the Ruby driver version 2.19 and above, the automatic encryption +shared library should be installed by following the instructions on the +:manual:`Automatic Encryption Shared Library for Queryable Encryption +` +page in the Server manual. The steps required are as follows: @@ -253,9 +255,9 @@ Now we can tell Mongoid what should be encrypted: Known Limitations ~~~~~~~~~~~~~~~~~ -* MongoDB CSFLE has some limitations that are described in - `the server documentation. `_ - These limitations also apply to Mongoid. +* MongoDB CSFLE has some limitations that are described on the + :manual:`CSFLE Limitations ` + page in the Server manual. These limitations also apply to Mongoid. * Mongoid does not support encryption of ``embeds_many`` relations. * If you use ``:key_name_field`` option, the field must be encrypted using non-deterministic algorithm. To encrypt your field deterministically, you must diff --git a/lib/config/locales/en.yml b/lib/config/locales/en.yml index dcf17ef46..02edd9e83 100644 --- a/lib/config/locales/en.yml +++ b/lib/config/locales/en.yml @@ -710,3 +710,14 @@ en: %{document} when the child '%{relation}' still has documents in it." resolution: "Don't attempt to delete the parent %{document} when it has children, or change the dependent option on the association." + client_session_mismatch: + message: "%{model} used within another client's session" + summary: > + Each model is associated with a client. Each session (transaction) + is also associated with a client. You've attempted to create or + update a model within a session associated with a different client. + This may be a bug in your code. + resolution: > + Either process the %{model} model outside the enclosing + transaction, or open a new transaction for that model before + performing the create/update. diff --git a/lib/mongoid/errors/mongoid_error.rb b/lib/mongoid/errors/mongoid_error.rb index e4b6a5917..161f65eb3 100644 --- a/lib/mongoid/errors/mongoid_error.rb +++ b/lib/mongoid/errors/mongoid_error.rb @@ -26,9 +26,9 @@ def compose_message(key, attributes = {}) @summary_title = translate('summary_title', {}) @resolution_title = translate('resolution_title', {}) - "\n#{@problem_title}:\n #{@problem}" \ - "\n#{@summary_title}:\n #{@summary}" \ - "\n#{@resolution_title}:\n #{@resolution}" + "\n#{@problem_title}:\n #{@problem&.strip}" \ + "\n#{@summary_title}:\n #{@summary&.strip}" \ + "\n#{@resolution_title}:\n #{@resolution&.strip}" end private diff --git a/upload-api-docs b/upload-api-docs index a24d24613..589a23355 100755 --- a/upload-api-docs +++ b/upload-api-docs @@ -7,7 +7,7 @@ gemfile true do source 'https://rubygems.org' gem 'nokogiri' gem 'aws-sdk-s3' - gem 'yard' + gem 'yard', '>= 0.9.35' end require 'aws-sdk-s3' @@ -29,6 +29,7 @@ class FileUploader end def upload_docs + puts "Uploading to #{@bucket}" Dir.glob("#{@docs_path}/**/*").each do |file| next if File.directory?(file) @@ -115,6 +116,12 @@ def generate_docs(options) '--readme', './README.md', '-o', options[:docs_path] ) + + begin + File.delete(File.join(options[:docs_path], 'frames.html')) + rescue StandardError + nil + end end options = Options.new