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 }