Mongodb文档重命名字段不起作用 [英] Mongodb document rename field not working
问题描述
{
一般:{
设置:[
{
名称:{
MetaData:{
type : bool
}
}
},
{
名称:{
MetaData:{
type: bool
}
}
},
{
名称:{
MetaData:{
type: bool
}
}
}
]
}
}
i有上述文件我需要更新General.Setting。[index ] .Name.MetaData.type to General.Setting。[index] .Name.MetaData.Newtype
我尝试过:
i尝试使用此查询:
第一种方法:
doc.forEach(function(d){
var settingsCollectionJSON = d.General.Setting;
settingsCollectionJSON.forEach(function(temp){
var settingsCollectionJSONobj = temp.Name.MetaData.Loc alizable;
db.getCollection('SettingCollection')。update(temp,{$ rename:{Name.MetaData.type:Name.MetaData.Newtype}})
})
})
使用$ set和$ unset的第二种方法。
//db.getCollection('SettingCollection').update(temp, {$ set:{'MetaData.0.type':settingsCollectionJSONobj},$ unset:{'MetaData.0.Newtype':1} })
但对于这些我没有得到更新。我有任何解决方案吗?
< blockquote> rename:{Name.MetaData.type:Name.MetaData.Newtype}})
})
} )
第二种方法使用
set和
取消设置。
//db.getCollection('SettingCollection').update(temp, {
{
"General": {
"Setting": [
{
"Name": {
"MetaData": {
"type": "bool"
}
}
},
{
"Name": {
"MetaData": {
"type": "bool"
}
}
},
{
"Name": {
"MetaData": {
"type": "bool"
}
}
}
]
}
}
i have the above document i need to update General.Setting.[index].Name.MetaData.type to General.Setting.[index].Name.MetaData.Newtype
What I have tried:
i did tried using this query :
1st approach:
doc.forEach( function(d) {
var settingsCollectionJSON = d.General.Setting;
settingsCollectionJSON.forEach( function(temp) {
var settingsCollectionJSONobj = temp.Name.MetaData.Localizable;
db.getCollection('SettingCollection').update(temp, { $rename: { "Name.MetaData.type": "Name.MetaData.Newtype" } })
})
})
2nd approach using $set and $unset.
//db.getCollection('SettingCollection').update(temp, { $set:{'MetaData.0.type':settingsCollectionJSONobj}, $unset: {'MetaData.0.Newtype':1} })
but for both these i'm not getting updated.can i have any solution?
rename: { "Name.MetaData.type": "Name.MetaData.Newtype" } })
})
})
2nd approach using
set and
unset.
//db.getCollection('SettingCollection').update(temp, {
这篇关于Mongodb文档重命名字段不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!