@@ -13,6 +13,8 @@ Field Definition
13
13
:class: singlecol
14
14
15
15
16
+ .. _field-types:
17
+
16
18
Field Types
17
19
===========
18
20
@@ -1151,3 +1153,48 @@ you can include the short versions of the modules.
1151
1153
include Mongoid::Document
1152
1154
include Mongoid::Timestamps::Updated::Short # For u_at only.
1153
1155
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