[DOCS-64] $rename documentation should explain the behavior when the original field isn't present Created: 13/Oct/11 Updated: 30/Oct/23 Resolved: 03/Oct/12 |
|
| Status: | Closed |
| Project: | Documentation |
| Component/s: | manual |
| Affects Version/s: | None |
| Fix Version/s: | Server_Docs_20231030 |
| Type: | Improvement | Priority: | Minor - P4 |
| Reporter: | Neil Sanchala | Assignee: | Kay Kim (Inactive) |
| Resolution: | Done | Votes: | 0 |
| Labels: | update | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Issue Links: |
|
||||||||
| Participants: | |||||||||
| Days since reply: | 11 years, 18 weeks, 2 days ago | ||||||||
| Description |
|
The documentation at http://www.mongodb.org/display/DOCS/Updating#Updating-%24rename doesn't specify the behavior of $rename when the source field doesn't exist and the destination field does exist. I believe the current behavior is to unset the destination, which was very surprising to me at least. Thanks! |
| Comments |
| Comment by Kay Kim (Inactive) [ 15/Oct/12 ] |
|
Hi Philipp – Regards, |
| Comment by auto [ 11/Oct/12 ] |
|
Author: {u'date': u'2012-10-11T14:08:00-07:00', u'email': u'samk@10gen.com', u'name': u'Sam Kleinman'}Message: merge: |
| Comment by auto [ 11/Oct/12 ] |
|
Author: {u'date': u'2012-10-10T15:20:01-07:00', u'email': u'kay.kim@10gen.com', u'name': u'kay'}Message: |
| Comment by auto [ 09/Oct/12 ] |
|
Author: {u'date': u'2012-10-09T12:54:56-07:00', u'email': u'samk@10gen.com', u'name': u'Sam Kleinman'}Message: |
| Comment by auto [ 09/Oct/12 ] |
|
Author: {u'date': u'2012-10-09T12:47:43-07:00', u'email': u'samk@10gen.com', u'name': u'Sam Kleinman'}Message: merge: |
| Comment by auto [ 09/Oct/12 ] |
|
Author: {u'date': u'2012-10-09T11:56:04-07:00', u'email': u'kay.kim@10gen.com', u'name': u'kay'}Message: |
| Comment by auto [ 04/Oct/12 ] |
|
Author: {u'date': u'2012-10-04T13:55:55-07:00', u'email': u'samk@10gen.com', u'name': u'Sam Kleinman'}Message: |
| Comment by auto [ 04/Oct/12 ] |
|
Author: {u'date': u'2012-10-04T13:11:18-07:00', u'email': u'samk@10gen.com', u'name': u'Sam Kleinman'}Message: merge: |
| Comment by auto [ 04/Oct/12 ] |
|
Author: {u'date': u'2012-10-03T14:52:30-07:00', u'email': u'kay.kim@10gen.com', u'name': u'kay'}Message: |
| Comment by Kay Kim (Inactive) [ 04/Oct/12 ] |
|
Hi Philipp – the changes have not yet been merged. Will let you know once it has been merged and published. Regards, Kay |
| Comment by Philipp Heinze [ 04/Oct/12 ] |
|
After looking into the documentation I can't see any change in regards to rename. Could you please point out where this clarification did go to, or repeat it here? Thank you! |
| Comment by Philipp Heinze [ 01/Jun/12 ] |
|
I've escalated this ticket into a Bug ticket for SERVER. You can find it here: SERVER-5983 |
| Comment by Neil Sanchala [ 31/May/12 ] |
|
I agree that it feels more like a bug. Eliot didn't when we discussed it, and he suggested opening this docs ticket. It's possible we didn't properly explain the issue there with minimal repro cases. |
| Comment by Neil Sanchala [ 31/May/12 ] |
|
(I got that shell output running against a 2.0.4 server.) |
| Comment by Neil Sanchala [ 31/May/12 ] |
|
Sorry, my initial description wasn't sufficient. There have to be multiple renames, where one actually does a rename. > db.test.save( {a: 1, b: 2, c: 3}) > db.test.update({}, {$rename: {"a":"b", "nonexistent": "c"}}) |
| Comment by Philipp Heinze [ 31/May/12 ] |
|
What I've found out is that existent fields are dropped, when all fields of the rename target and rename source subdocument are referenced in $rename. Those fields non existent in the source subdoc will cause the target fields to be unset. db.c.save({b: {a :1},d: {c:2}}) }}) , } , "d" : { } } This does not happen if I do the following: db.c.save({b: {a :1,e:2},d: {c:2}}) }}) , } , "d" : { } } This behavior can be spottet as well with this: ,d: {c:2, f: 3}}) }}) , } , "d" : { "f" : 3 }} So I may consider this behavior as bug, as it's not consistent, which can cause severe problems if you trust on some common terms of Operation. |
| Comment by Philipp Heinze [ 31/May/12 ] |
|
With MongoDB 2.0.3 a $rename of a non existent field, doesn't causes that the field, if existent, will be unset. What version did you use? db.c.save({m:{a:1}}) }}) } }}) , } }}) , } }}) , } }}) , } |