MongoDB的阵列中的重命名数据库字段 [英] MongoDB rename database field within array

查看:780
本文介绍了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
)

但它返回: $重命名源可能不是动态数组

推荐答案

如文档中提到的有没有办法重命名的数组中的字段。你唯一的选择是遍历您的收藏文件,阅读和更新每个$未设置旧/ $设置新的业务。

As mentioned in the documentation there is no way to rename fields within arrays. Your only option is to iterate over your collection documents, read them and update each with $unset old/$set new operations.

这篇关于MongoDB的阵列中的重命名数据库字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆