I need to rename indentifier in this:

{ "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
)

but it returns: $rename source may not be dynamic array.

推荐答案

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.

Json相关问答推荐

将json数组反序列化为选项 struct

您可以使用Jolt对JSON执行OR条件吗

JSON字符串处理注入引号

最新版本的Deneb在数据溢出时不支持滚动

在 VS Code 中将一个正则表达式替换为另一个正则表达式

使用 Groovy 将 XML 转换为 JSON

如何在 Dart 中与多个 map (字典)相交

根据数据框中的其他列值将列表 json 对象插入行

下一个 Js 部署在 getStaticPath 函数上失败:在 JSON.parse 的位置 0 的 JSON 中出现意外的令牌 < 但在本地运行

以 JSON 格式访问(新型、公共)Google 工作表

为什么在测试 RSPEC 时 JBuilder 不返回 JSON 中的响应正文

JSON RPC - 什么是id?

Java的JSON字符串整洁/格式化程序

数据包含连续问号时无法理解的 jQuery $.ajax() 行为

嵌套 JSON:如何向对象添加(推送)新项目?

通过 JSON 发送 HTML 代码

使用 application/json 优于 text/plain 的优势?

JSON 模式 - 如果对象*不*包含特定属性则有效

JSON.stringify 向我的 Json 对象添加额外的 \ 和 "" 的问题

无法解析 JSON 文件中的 TAB