I went through this link: How to rename a document field in a MongoDB?, but its not working fine for me. I've Mongo Document like below. I am using MongoDB server version: 4.0.3
.
{
"_id" : ObjectId("5cb825e566135255e0bf38a4"),
"firstName" : "John",
"lastName" : "svc_user",
.....
.....
"status" : "A",
"effDate" : ISODate("2012-08-24T01:46:33.000Z"),
"department" : [
{
"deptName" : "KG",
....
....
},
...
....
.....
],
...
...
...
}
I executed the below query:
db.employee.update({}, {$rename:{"department.deptName":"department.departmentName"}}, false, true);
Error: cannot use the part (department of department.deptName) to traverse the element