MongoDB重命名数组中的数据库字段 [英] MongoDB rename database field within array
本文介绍了MongoDB重命名数组中的数据库字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要重命名indentifier
:
{ "general" :
{ "files" :
{ "file" :
[
{ "version" :
{ "software_program" : "MonkeyPlus",
"indentifier" : "6.0.0"
}
}
]
}
}
}
我试过了
db.nrel.component.update(
{},
{ $rename: {
"general.files.file.$.version.indentifier" : "general.files.file.$.version.identifier"
} },
false, true
)
但它返回:$rename source may not be dynamic array
.
推荐答案
如文档中所述,无法使用单个命令直接重命名数组中的字段.您唯一的选择是遍历您的集合文档,阅读它们并使用 $unset
old/$set
new 操作更新每个文档.
As mentioned in the documentation there is no way to directly rename fields within arrays with a single command. Your only option is to iterate over your collection documents, read them and update each with $unset
old/$set
new operations.
这篇关于MongoDB重命名数组中的数据库字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文