Skip to content

Commit

Permalink
MONGOID-5721 - Update documentation and tests to remove references to…
Browse files Browse the repository at this point in the history
… MongoDB server 3.4 and prior (#5762)
  • Loading branch information
johnnyshields authored Jan 15, 2024
1 parent 0ab88b9 commit 8d458e9
Show file tree
Hide file tree
Showing 21 changed files with 45 additions and 173 deletions.
58 changes: 19 additions & 39 deletions docs/reference/associations.txt
Original file line number Diff line number Diff line change
Expand Up @@ -693,30 +693,22 @@ Querying Loaded Associations
````````````````````````````

Mongoid query methods can be used on embedded associations of documents which
are already loaded in the application. This mechanism is sometimes called
"embedded matching" or "embedded document matching" and it is implemented
entirely in Mongoid - the queries are NOT sent to the server.

Embedded matching is supported for most general-purpose query operators. It
is not implemented for :ref:`text search <text-search>`, :manual:`geospatial query
operators </reference/operator/query-geospatial/>`,
operators that execute JavaScript code (:manual:`$where </reference/operator/query/where/>`)
and operators that are implemented via other server functionality such as
:manual:`$expr <https://mongodb.com/docs/manual/reference/operator/query/expr/>`
and :manual:`$jsonSchema <https://mongodb.com/docs/manual/reference/operator/query/jsonSchema/>`.
are already loaded in the application. This mechanism is called
"embedded matching" and it is implemented entirely in Mongoid--the queries
are NOT sent to the server.

The following operators are supported:

- :manual:`Bitwise operators </reference/operator/query-bitwise/>`
- :manual:`Comparison operators </reference/operator/query-comparison/>`
- :manual:`Logical operators </reference/operator/query-logical/>`
- :manual:`$comment </reference/operator/query/comment/>`
- :manual:`Array query operators </reference/operator/query-array/>`
- :manual:`$exists </reference/operator/query/exists/>`
- :manual:`$mod </reference/operator/query/mod/>`
- :manual:`$type </reference/operator/query/type/>`
- :manual:`$regex </reference/operator/query/regex/>` (``$options`` field
is only supported when the ``$regex`` argument is a string)
- :manual:`Array query operators </reference/operator/query-array/>`
- :manual:`Bitwise operators </reference/operator/query-bitwise/>`
- :manual:`$comment </reference/operator/query/comment/>`

For example, using the model definitions just given, we could query
tours on a loaded band:
Expand All @@ -726,33 +718,19 @@ tours on a loaded band:
band = Band.where(name: 'Astral Projection').first
tours = band.tours.where(year: {'$gte' => 2000})

Embedded Matching Vs Server Behavior
Embedded Matching vs Server Behavior
````````````````````````````````````

Mongoid aims to provide the same semantics when performing embedded matching
as those of MongoDB server. This means, for example, when the server only
accepts arguments of particular types for a particular operator, Mongoid
would also only accept arguments of the corresponding types.

The following deviations are known:

- Mongoid embedded matchers, because they are implemented on the client side,
behave the same regardless of the server version that backs the application.
As such, it is possible for Mongoid to deviate from server behavior if
the server itself behaves differently in different versions. All operators are implemented in
Mongoid regardless of backing deployment's server version.

As of this writing, the known cases of such deviation are:

- 3.2 and earlier servers not validating ``$size`` arguments as strictly as newer versions do.
- 4.0 and earlier servers not validating ``$type`` arguments as strictly as newer versions
do (allowing invalid arguments like 0, for example).
- 3.2 and earlier servers not supporting ``Decimal128`` for ``$type``, as well as allowing invalid
arguments such as negative numbers (smaller than -1) and numbers that are greater than 19
(not including 127, the argument for the ``MaxKey`` type).
- 3.4 and earlier servers not supporting arrays for ``$type``.
- 3.0 and earlier servers not supporting bitwise operators.
Mongoid's embedded matching aims to support the same functionality and
semantics as native queries on the latest MongoDB server version.
Note the following known limitations:

- Embedded matching is not implemented for :ref:`text search <text-search>`,
:manual:`geospatial query operators </reference/operator/query-geospatial/>`,
operators that execute JavaScript code (:manual:`$where </reference/operator/query/where/>`)
and operators that are implemented via other server functionality such as
:manual:`$expr <https://mongodb.com/docs/manual/reference/operator/query/expr/>`
and :manual:`$jsonSchema <https://mongodb.com/docs/manual/reference/operator/query/jsonSchema/>`.

- Mongoid DSL expands ``Range`` arguments to hashes with ``$gte`` and ``$lte``
conditions. `In some cases <https://jira.mongodb.org/browse/MONGOID-4908>`_
Expand All @@ -764,7 +742,9 @@ The following deviations are known:
possible <https://jira.mongodb.org/browse/MONGOID-4936>`_ to specify a
regular expression object as the pattern and also provide options.

In general, Mongoid adopts the behavior of current server versions and validates more strictly.
- MongoDB Server 4.0 and earlier servers do not validate ``$type`` arguments strictly
(for example, allowing invalid arguments like 0). This is validated more strictly on
the client side.


.. _omit-id:
Expand Down
20 changes: 11 additions & 9 deletions docs/reference/configuration.txt
Original file line number Diff line number Diff line change
Expand Up @@ -171,10 +171,12 @@ for details on driver options.
# roles:
# - 'dbOwner'

# Change the default authentication mechanism. Valid options are: :scram,
# :mongodb_cr, :mongodb_x509, and :plain. Note that all authentication
# mechanisms require username and password, with the exception of :mongodb_x509.
# Default is :scram since MongoDB 3.0; earlier versions defaulted to :plain.
# Change the default authentication mechanism. Valid options include:
# :scram, :scram256, :mongodb_cr, :mongodb_x509, :gssapi, :aws, :plain.
# MongoDB Server defaults to :scram, which will use "SCRAM-SHA-256" if available,
# otherwise fallback to "SCRAM-SHA-1" (:scram256 will always use "SCRAM-SHA-256".)
# This setting is handled by the MongoDB Ruby Driver. Please refer to:
# https://mongodb.com/docs/ruby-driver/current/reference/authentication/
# auth_mech: :scram

# The database or source to authenticate the user against.
Expand Down Expand Up @@ -263,10 +265,10 @@ for details on driver options.
# the setting is ignored.
# allow_bson5_decimal128: false

# Application name that is printed to the mongodb logs upon establishing
# a connection in server versions >= 3.4. Note that the name cannot
# exceed 128 bytes. It is also used as the database name if the
# database name is not explicitly defined.
# Application name that is printed to the MongoDB logs upon establishing
# a connection. Note that the name cannot exceed 128 bytes in length.
# It is also used as the database name if the database name is not
# explicitly defined. (default: nil)
# app_name: nil

# When this flag is false, callbacks for embedded documents will not be
Expand All @@ -280,7 +282,7 @@ for details on driver options.
# around_callbacks_for_embeds: false

# Sets the async_query_executor for the application. By default the thread pool executor
# is set to `:immediate. Options are:
# is set to `:immediate`. Options are:
#
# - :immediate - Initializes a single +Concurrent::ImmediateExecutor+
# - :global_thread_pool - Initializes a single +Concurrent::ThreadPoolExecutor+
Expand Down
3 changes: 1 addition & 2 deletions docs/reference/queries.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1422,8 +1422,7 @@ Mongoid also has some helpful methods on criteria.
*Find documents for a provided JavaScript expression, optionally with
the specified variables added to the evaluation scope. The scope
argument is supported in MongoDB 4.2 and lower.*
*In MongoDB 3.6 and higher, prefer* :manual:`$expr
</reference/operator/query/expr/>` *over* ``for_js``.
*Prefer* :manual:`$expr </reference/operator/query/expr/>` *over* ``for_js``.

-
.. code-block:: ruby
Expand Down
11 changes: 4 additions & 7 deletions docs/reference/sessions.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,10 @@ Sessions
:depth: 2
:class: singlecol

Versions 3.6 and higher of the MongoDB server support sessions. You can use sessions with Mongoid in a similar way
that you would execute a transaction in ActiveRecord. Namely, you can call a method, ``#with_session`` on a model class
or on an instance of a model and execute some operations in a block. All operations in the block will be
executed in the context of single session. Please see the MongoDB Ruby driver documentation for what session options
are available.
You can use sessions with Mongoid in a similar way that you would execute a transaction in ActiveRecord.
Namely, you can call a method, ``#with_session`` on a model class or on an instance of a model and execute
some operations in a block. All operations in the block will be executed in the context of single session.
Please see the MongoDB Ruby driver documentation for what session options are available.

Please note the following limitations of sessions:

Expand All @@ -26,8 +25,6 @@ Please note the following limitations of sessions:

- All model classes and instances used within the session block must use the same driver client. For example, if you have specified different ``storage_options`` for another model used in the block than that of the model class or instance on which ``#with_session`` is called, you will get an error.

- All connected MongoDB servers must be version 3.6 or higher.

Using a Session via Model#with_session
======================================

Expand Down
8 changes: 4 additions & 4 deletions lib/mongoid/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ module Config

LOCK = Mutex.new

# Application name that is printed to the mongodb logs upon establishing
# a connection in server versions >= 3.4. Note that the name cannot
# exceed 128 bytes. It is also used as the database name if the
# database name is not explicitly defined.
# Application name that is printed to the MongoDB logs upon establishing
# a connection. Note that the name cannot exceed 128 bytes in length.
# It is also used as the database name if the database name is not
# explicitly defined.
option :app_name, default: nil

# (Deprecated) In MongoDB 4.0 and earlier, set whether to create
Expand Down
10 changes: 6 additions & 4 deletions lib/rails/generators/mongoid/config/templates/mongoid.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,12 @@ development:
# roles:
# - 'dbOwner'

# Change the default authentication mechanism. Valid options are: :scram,
# :mongodb_cr, :mongodb_x509, and :plain. Note that all authentication
# mechanisms require username and password, with the exception of :mongodb_x509.
# Default is :scram since MongoDB 3.0; earlier versions defaulted to :plain.
# Change the default authentication mechanism. Valid options include:
# :scram, :scram256, :mongodb_cr, :mongodb_x509, :gssapi, :aws, :plain.
# MongoDB Server defaults to :scram, which will use "SCRAM-SHA-256" if available,
# otherwise fallback to "SCRAM-SHA-1" (:scram256 will always use "SCRAM-SHA-256".)
# This setting is handled by the MongoDB Ruby Driver. Please refer to:
# https://mongodb.com/docs/ruby-driver/current/reference/authentication/
# auth_mech: :scram

# The database or source to authenticate the user against.
Expand Down
15 changes: 0 additions & 15 deletions spec/integration/matcher_operator_data/bits_all_clear.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
a:
$bitsAllClear: 35
matches: true
min_server_version: 3.2

- name: existing field - does not match with int
document:
Expand All @@ -16,7 +15,6 @@
a:
$bitsAllClear: 24
matches: false
min_server_version: 3.2

- name: existing field - matches with binData
document:
Expand All @@ -29,7 +27,6 @@
IW==
type: :generic
matches: true
min_server_version: 3.2

- name: existing field - does not match with binData
document:
Expand All @@ -42,7 +39,6 @@
IW==
type: :generic
matches: false
min_server_version: 3.2

- name: existing binData field matches
document:
Expand All @@ -54,7 +50,6 @@
a:
$bitsAllClear: 20
matches: true
min_server_version: 3.2

- name: existing binData field does not match
document:
Expand All @@ -66,7 +61,6 @@
a:
$bitsAllClear: 15
matches: false
min_server_version: 3.2

- name: existing field - matches with array
document:
Expand All @@ -76,7 +70,6 @@
a:
$bitsAllClear: [0, 3]
matches: true
min_server_version: 3.2

- name: existing field - does not match with array
document:
Expand All @@ -86,7 +79,6 @@
a:
$bitsAllClear: [0, 2]
matches: false
min_server_version: 3.2

- name: float condition representable as an integer
document:
Expand All @@ -96,7 +88,6 @@
a:
$bitsAllClear: 35.0
matches: true
min_server_version: 3.2

- name: float condition not representable as an integer
document:
Expand All @@ -106,7 +97,6 @@
a:
$bitsAllClear: 35.1
error: true
min_server_version: 3.2

- name: string condition
document:
Expand All @@ -116,7 +106,6 @@
a:
$bitsAllClear: hello
error: true
min_server_version: 3.2

- name: empty array condition
document:
Expand All @@ -126,7 +115,6 @@
a:
$bitsAllClear: []
matches: true
min_server_version: 3.2

- name: integer 0 condition
document:
Expand All @@ -136,7 +124,6 @@
a:
$bitsAllClear: 0
matches: true
min_server_version: 3.2

- name: negative integer condition
document:
Expand All @@ -146,7 +133,6 @@
a:
$bitsAllClear: -1
error: true
min_server_version: 3.2

- name: negative float condition
document:
Expand All @@ -156,4 +142,3 @@
a:
$bitsAllClear: -1.0
error: true
min_server_version: 3.2
Loading

0 comments on commit 8d458e9

Please sign in to comment.