Step One
> db.myCollection.find();
{ "_id" : ObjectId("2358523892345"), "field1" : "value 1", "field2" : [ { "subfield1" : "value 2" }, { "Subfield2" : "value 3" } ], "field3" : "value 4" }
I am wanting to rename the field Subfield2
to subfield2
. I tried:
Step Two
> db.myCollection.update ( { "field3": "value 4" }, {$rename: {"Subfield2": "subfield2" } } )
And then ran find() again and get the same results as in 'Step One' ie the field is not renamed.
Using MongoDB terminology, I think what I am trying to do is 'rename a field in an embedded document in an array'.
References