[SERVER-11531] Cannot $rename to/from an array field Created: 01/Nov/13  Updated: 11/Jul/16  Resolved: 14/Nov/13

Status: Closed
Project: Core Server
Component/s: Write Ops
Affects Version/s: 2.5.3
Fix Version/s: 2.5.4

Type: Bug Priority: Major - P3
Reporter: David Storch Assignee: Scott Hernandez (Inactive)
Resolution: Done Votes: 0
Labels: 26qa
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
Operating System: ALL
Participants:

 Description   

Expected: $rename field 'a' to field 'b' should replace field 'b' if it already exists, regardless of the data type stored at 'b'.

Actual: If 'b' is an array, then the $rename returns an error instead.

Example:

> db.x.save({_id: 1, a: 2, b: []})
> db.x.update({_id: 1}, {$rename: {a: "b"}})
The destination field cannot be an array element, 'a' in doc with _id: 1.0 has an array field called 'b'
> db.x.findOne()
{ "_id" : 1, "a" : 2, "b" : [ ] }

On the other hand, if "b" stores an object instead of an array, this works as expected:

> db.x.save({_id: 1, a: 2, b: {}})
> db.x.update({_id: 1}, {$rename: {a: "b"}})
> db.x.findOne()
{ "_id" : 1, "b" : 2 }



 Comments   
Comment by Githook User [ 14/Nov/13 ]

Author:

{u'username': u'scotthernandez', u'name': u'Scott Hernandez', u'email': u'scotthernandez@gmail.com'}

Message: SERVER-11531, SERVER-10489, SERVER-6835, SERVER-4830: Refactor update system to support immutable fields, consolodate storage validation, and misc issues.
Branch: master
https://github.com/mongodb/mongo/commit/b98712c551e8ab27c33e1a5e7c694fa36c3334ce

Generated at Thu Feb 08 03:26:01 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.