【发布时间】:2020-05-25 17:29:46
【问题描述】:
我浏览了这个链接:How to rename a document field in a MongoDB?,但它对我来说不能正常工作。我有如下的 Mongo 文档。我正在使用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",
....
....
},
...
....
.....
],
...
...
...
}
我执行了以下查询:
db.employee.update({}, {$rename:{"department.deptName":"department.departmentName"}}, false, true);
错误: 不能使用part(department of department.deptName)遍历元素
【问题讨论】:
-
对于嵌入文档中的字段,$rename 运算符可以重命名这些字段以及将字段移入和移出嵌入文档。如果这些字段位于数组元素中,则 $rename 不起作用。请显示此链接docs.mongodb.com/manual/reference/operator/update/rename
标签: mongodb