1
- ====================================
2
- Field Names with (``.``) and (``$``)
3
- ====================================
1
+ =========================================================
2
+ Field Names with Periods (``.``) and Dollar Signs (``$``)
3
+ =========================================================
4
4
5
5
.. default-domain:: mongodb
6
6
@@ -15,9 +15,9 @@ Field Names with (``.``) and (``$``)
15
15
Overview
16
16
--------
17
17
18
- MongoDB 5.0 adds improved support for field names that are (``$``)
19
- prefixed or that contain (``.``) characters . The validation rules for
20
- storing data have been updated to make it easier to work with data
18
+ MongoDB 5.0 adds improved support for field names that are dollar
19
+ (``$``) prefixed or that contain periods (``.``). The validation rules
20
+ for storing data have been updated to make it easier to work with data
21
21
sources that use these characters.
22
22
23
23
In most cases data that has been stored using field names like these
@@ -27,13 +27,13 @@ is not directly accessible. You need to use helper methods like
27
27
28
28
The field name validation rules are not the same for all types of
29
29
storage operations. This page summarizes how different insert and
30
- update operations handle (``$``) prefixed field names.
30
+ update operations handle dollar (``$``) prefixed field names.
31
31
32
32
Insert operations
33
33
-----------------
34
34
35
- (``$``) prefixed fields are permitted as top level and nested field
36
- names for inserts.
35
+ Dollar (``$``) prefixed fields are permitted as top level and nested
36
+ field names for inserts.
37
37
38
38
.. code-block:: javascript
39
39
:emphasize-lines: 3
@@ -43,7 +43,7 @@ names for inserts.
43
43
"quantity": 30
44
44
} )
45
45
46
- (``$``) prefixed fields are permitted on inserts using otherwise
46
+ Dollar (``$``) prefixed fields are permitted on inserts using otherwise
47
47
reserved words. Operator names like :update:`$inc` can be used as
48
48
field names as well as words like ``id``, ``db``, and ``ref``.
49
49
@@ -60,16 +60,16 @@ field names as well as words like ``id``, ``db``, and ``ref``.
60
60
61
61
An update which creates a new document during an :term:`upsert` is
62
62
treated as an ``insert`` rather than an ``update`` for field name
63
- validation. :term:`Upserts <upsert>` can accept (``$``) prefixed
63
+ validation. :term:`Upserts <upsert>` can accept dollar (``$``) prefixed
64
64
fields. However, :term:`upserts <upsert>` are a special case and
65
65
similar update operations may cause an error if the ``match`` portion
66
66
of the update selects an existing document.
67
67
68
68
This code sample has ``upsert: true`` so it will insert a new document
69
69
if the collection doesn't already contain a document that matches the
70
70
query term, ``{ "date": "2021-07-07" }``. If this sample code matches
71
- an existing document, the update will fail since ``$hotel`` is (``$``)
72
- prefixed.
71
+ an existing document, the update will fail since ``$hotel`` is dollar
72
+ (``$``) prefixed.
73
73
74
74
.. code-block:: javascript
75
75
:emphasize-lines: 5
@@ -88,8 +88,8 @@ Document Replacing Updates
88
88
89
89
Update operators either replace existing fields with new documents
90
90
or else modify those fields. In cases where the update performs a
91
- replacement, (``$``) prefixed fields are not permitted as top level
92
- field names.
91
+ replacement, dollar (``$``) prefixed fields are not permitted as top
92
+ level field names.
93
93
94
94
Consider a document like
95
95
@@ -119,14 +119,14 @@ modify the ``address.$street`` field but you could not update the
119
119
)
120
120
121
121
Use :expression:`$setField` as part of an aggregation pipeline to
122
- :ref:`update top level <dotDollar-aggregate-update>` (``$``) prefixed
123
- fields like ``$rooms``.
122
+ :ref:`update top level <dotDollar-aggregate-update>` dollar (``$``)
123
+ prefixed fields like ``$rooms``.
124
124
125
125
Document Modifying Updates
126
126
--------------------------
127
127
128
128
When an update modifies, rather than replaces, existing document
129
- fields, (``$``) prefixed fields can be top level field names.
129
+ fields, dollar (``$``) prefixed fields can be top level field names.
130
130
Subfields can be accessed directly, but you need a helper method to
131
131
access the top level fields.
132
132
@@ -178,7 +178,7 @@ Updates Using Aggregation Pipelines
178
178
179
179
Use :expression:`$setField`, :expression:`$getField`, and
180
180
:expression:`$literal` in the :pipeline:`$replaceWith` stage to modify
181
- (``$``) prefixed fields in an aggregation :term:`pipeline`.
181
+ dollar (``$``) prefixed fields in an aggregation :term:`pipeline`.
182
182
183
183
Consider a collection of school records like:
184
184
@@ -193,7 +193,7 @@ Consider a collection of school records like:
193
193
}
194
194
195
195
Create a new collection for the spring semester using a
196
- :term:`pipeline` to update the (``$``) prefixed ``$term`` field.
196
+ :term:`pipeline` to update the dollar (``$``) prefixed ``$term`` field.
197
197
198
198
.. code-block:: javascript
199
199
:emphasize-lines: 3-5
@@ -213,8 +213,8 @@ General Restrictions
213
213
--------------------
214
214
215
215
In addition to the storage validation rules above, there are some
216
- general restrictions on using (``$``) prefixed field names. These
217
- fields cannot:
216
+ general restrictions on using dollar (``$``) prefixed field names.
217
+ These fields cannot:
218
218
219
219
- Be indexed
220
220
- Be used as part of a shard key
@@ -226,3 +226,5 @@ fields cannot:
226
226
227
227
.. include:: /includes/warning-possible-data-loss.rst
228
228
229
+ .. include:: /includes/warning-dot-dollar-import-export.rst
230
+
0 commit comments