{ 一般:{ 设置:[ { 名称:{ 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} }) 但对于这些我没有得到更新。我有任何解决方案吗?
解决方案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 usingset andunset. //db.getCollection('SettingCollection').update(temp, {更多推荐
Mongodb文档重命名字段不起作用
发布评论