6
6
7
7
.. operator:: $rename
8
8
9
+ .. versionadded:: 1.7.2
10
+
9
11
*Syntax*: ``{$rename: { <old name1>: <new name1>, <old name2>: <new name2>, ... } }``
10
12
11
13
The :operator:`$rename` operator updates the name of a field. The
@@ -47,7 +49,7 @@ $rename
47
49
48
50
db.students.update( { _id: 1 }, { $rename: { "nmae": "name" } } )
49
51
50
- The operation renames the sub-document ``nmae`` to ``name``:
52
+ This operation renames the sub-document ``nmae`` to ``name``:
51
53
52
54
.. code-block:: javascript
53
55
@@ -67,7 +69,7 @@ $rename
67
69
68
70
db.students.update( { _id: 1 }, { $rename: { "name.first": "name.fname" } } )
69
71
70
- The operation renames the sub-document field ``first`` to ``fname``:
72
+ This operation renames the sub-document field ``first`` to ``fname``:
71
73
72
74
.. code-block:: javascript
73
75
@@ -87,7 +89,7 @@ $rename
87
89
88
90
db.students.update( { _id: 1 }, { $rename: { "name.last": "contact.lname" } } )
89
91
90
- The operation renames the sub-document field ``last`` to ``lname`` and
92
+ This operation renames the sub-document field ``last`` to ``lname`` and
91
93
moves it to the sub-document ``contact``:
92
94
93
95
.. code-block:: javascript
@@ -114,8 +116,8 @@ $rename
114
116
115
117
db.students.update( { _id: 1 }, { $rename: { 'wife': 'spouse' } } )
116
118
117
- The operation performs no action since the field with the name
118
- ``wife`` does not exist .
119
+ This operation does nothing because there is no field named
120
+ ``wife``.
119
121
120
122
- When renaming multiple fields and **all** of the old field names
121
123
refer to non-existing fields, the :operator:`$rename` operator
@@ -127,8 +129,8 @@ $rename
127
129
'vice': 'vp',
128
130
'office': 'term' } } )
129
131
130
- The operation performs no action since fields with the names
131
- ``wife``, ``vice``, and ``office`` do not exist .
132
+ This operation does nothing because there are no fields named
133
+ ``wife``, ``vice``, and ``office``.
132
134
133
135
- When renaming multiple fields and **some** but not all old field
134
136
names refer to non-existing fields, the :operator:`$rename`
@@ -150,7 +152,8 @@ $rename
150
152
db.students.update( { _id: 1 }, { $rename: { 'wife': 'alias',
151
153
'mobile': 'cell' } } )
152
154
153
- The operation renames the ``mobile`` field to ``cell``. No other
155
+ This operation renames the ``mobile`` field to ``cell``, and has
156
+ no other impact
154
157
action occurs.
155
158
156
159
.. code-block:: javascript
@@ -165,20 +168,21 @@ $rename
165
168
166
169
.. note::
167
170
168
- Before version 2.2, when renaming multiple fields and some but
169
- not all old field names refer to non-existing fields:
171
+ Before version 2.2, when renaming multiple fields and only some ( but
172
+ not all) old field names refer to non-existing fields:
170
173
171
174
- **if** no field exists with the new field name, the
172
175
:operator:`$rename` operator does nothing.
173
176
174
177
- **if** fields already exist with the new field names, the
175
178
:operator:`$rename` operator drops these fields.
176
179
177
- Consider the following query that renames both an existing
178
- field ``mobile`` and a non-existing field ``wife``. The
179
- non-existing field ``wife`` is to be set to ``alias``, a name
180
- that already exists.
181
-
180
+ Consider the following operation that renames both the
181
+ field ``mobile``, which exists, the field ``wife``, which
182
+ does not exist. The operation will set the
183
+ field named ``wife`` ``alias``, which is the name of an
184
+ existing field:
185
+
182
186
.. code-block:: javascript
183
187
184
188
db.students.update( { _id: 1 }, { $rename: { 'wife': 'alias', 'mobile': 'cell' } } )
@@ -194,5 +198,3 @@ $rename
194
198
"name" : { "lname" : "washington" },
195
199
"places" : { "d" : "Mt Vernon", "b" : "Colonial Beach" }
196
200
}
197
-
198
- .. versionadded:: 1.7.2
0 commit comments