$ rename-重命名嵌入式文档中的字段

时间:2019-07-10 10:14:45

标签: mongodb mongodb-query aggregation-framework

我正在尝试更改嵌入式文档密钥中的值,但不会发生更新。 我试图通过在Mongo Shell中使用以下命令来更新嵌入式文档中的密钥:

                                   id  val       date  calc
SE0000191827 2018-02-28  SE0000191827    8 2018-02-16  26.0
             2018-03-31           NaN  NaN        NaT  27.0
             2018-04-30  SE0000191827    7 2018-04-20  27.0
             2018-05-31           NaN  NaN        NaT   NaN
             2018-06-30           NaN  NaN        NaT   NaN
             2018-07-31  SE0000191827    6 2018-07-11   NaN
             2018-08-31           NaN  NaN        NaT   NaN
             2018-09-30           NaN  NaN        NaT   NaN
             2018-10-31  SE0000191827    5 2018-10-19   NaN
             2018-11-30           NaN  NaN        NaT   NaN
             2018-12-31  SE0000191827    9 2018-12-29   NaN
SE0000195570 2014-01-31  SE0000195570    4 2014-01-31  10.0
             2014-02-28           NaN  NaN        NaT   NaN
             2014-03-31           NaN  NaN        NaT   NaN
             2014-04-30  SE0000195570    3 2014-04-29   NaN
             2014-05-31           NaN  NaN        NaT   NaN
             2014-06-30           NaN  NaN        NaT   NaN
             2014-07-31  SE0000195570    2 2014-07-16   NaN
             2014-08-31           NaN  NaN        NaT   NaN
             2014-09-30           NaN  NaN        NaT   NaN
             2014-10-31  SE0000195570    1 2014-10-23   NaN

我希望db.TestCollection.update( {"_id: "1235647898eee4475"}, { $rename: { "welcome.ext.http://google&46;com/api/ext/extdisplay": "welcome.ext.http://google.com/api/ext/extdisplay" } } ) 取代$rename;在&46中,并在嵌入式“集合”文档中添加了Key

有人可以帮助他们在嵌入式文档中重命名它们,并对100k文档执行一些批量更新吗?

1 个答案:

答案 0 :(得分:0)

在MongoDB中,键名中不能包含点(。)。我假设您当前的结构是

{
  "welcome" : {
    "ext" : {
      "http://google&46;com/api/ext/extdisplay" : "some value"
    }
  }
}

,您想将其更改为

{
  "welcome" : {
    "ext" : {
      "http://google.com/api/ext/extdisplay" : "some value"
    }
  }
}

如果这是您的要求,那么对不起,它在MongoDB中不受支持