Skip to content

Commit b7b8651

Browse files
johnnyshieldsp
andauthored
MONGOID-5161 - [Documentation Only] Clarify the policy for working with . and $ named fields which were introduced in MongoDB 5.0 (#5051)
* MONGOID-???? - Documentation only. This clarifies the policy for working with . and $ named fields which were introduced in MongoDB 5.0 * Add reference * Update fields.txt * Update fields.txt * Update fields.txt * add sphinx note * rewrite the docs Co-authored-by: shields <[email protected]> Co-authored-by: Oleg Pudeyev <[email protected]>
1 parent 478ecd6 commit b7b8651

File tree

2 files changed

+50
-1
lines changed

2 files changed

+50
-1
lines changed

source/README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ tutorials and the reference.
77
To build the documentation locally for review, install `sphinx` and
88
`sphinx-book-theme`, then execute `make html` in this directory:
99

10-
pip install sphinx sphinx-book-theme
10+
pip install 'sphinx<4.3' sphinx-book-theme
1111
make html
1212

13+
Note: sphinx 4.3 is currently breaking when trying to render Mongoid
14+
documentation.

source/reference/fields.txt

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ Field Definition
1313
:class: singlecol
1414

1515

16+
.. _field-types:
17+
1618
Field Types
1719
===========
1820

@@ -1151,3 +1153,48 @@ you can include the short versions of the modules.
11511153
include Mongoid::Document
11521154
include Mongoid::Timestamps::Updated::Short # For u_at only.
11531155
end
1156+
1157+
1158+
.. _field-names-with-periods-and-dollar-signs:
1159+
1160+
Field Names with Dots/Periods (``.``) and Dollar Signs (``$``)
1161+
==============================================================
1162+
1163+
MongoDB query language (MQL) generally uses the dot/period character (``.``)
1164+
to separate field names in a field path that traverses embedded documents, and
1165+
the dollar character (``$``) for operators. It is possible to utilize field
1166+
names containing the dot and dollar characters, however it is recommended to
1167+
avoid these characters for ease of querying.
1168+
1169+
MongoDB 5.0 adds `special operators
1170+
<https://docs.mongodb.com/manual/core/dot-dollar-considerations/#std-label-crud-concepts-dot-dollar-considerations>`_
1171+
for querying and modifying documents using field names containing dots and
1172+
dollars. Previous MongoDB versions do not provide a mechanism for querying
1173+
documents on fields whose names contain dots and dollars, though such documents
1174+
can be retrieved verbatim (once they are matched using some other strategy).
1175+
1176+
Mongoid provides its own DSL for querying MongoDB and, unlike MongoDB 5.0,
1177+
Mongoid does not yet provide any facilities for querying documents using
1178+
field names containing dots and dollars. It is possible to query such documents
1179+
using MQL, but not via most Mongoid DSL methods. Additionally, there is
1180+
other code in Mongoid that assumes that the dot (``.``) separates path
1181+
components which may misbehave should a document contain a field with dots
1182+
in its name.
1183+
1184+
Historically, MongoDB drivers prohibited inserting documents with field names
1185+
containing dots and dollars, since such documents couldn't be queried via
1186+
those field names. This prohibition is now being lifted due to the new
1187+
operators introduced with MongoDB 5.0; however, the required changes in the
1188+
Ruby driver `have not yet been implemented
1189+
<https://jira.mongodb.org/browse/RUBY-2528>`_. By virtue of using the Ruby
1190+
driver to interact with the database, this prohibition on inserting documents
1191+
with field names containing dots and dollars also applies to Mongoid.
1192+
Thus, while both the Ruby driver and Mongoid permit querying documents that
1193+
have been inserted using other mechanisms by field names containing dots and
1194+
dollars, there is presently no possibility to insert such documents using
1195+
either Ruby driver or Mongoid.
1196+
1197+
To summarize, field names containing dots and dollars have limited support in
1198+
Mongoid, the Ruby MongoDB driver and MongoDB server. Such field names should
1199+
only be used when interfacing with software that already uses these names,
1200+
and should be avoided for new development.

0 commit comments

Comments
 (0)