【问题标题】:Mongodb change Document field nameMongoDB更改文档字段名称
【发布时间】:2015-07-16 16:03:53
【问题描述】:

我有一个应用程序读取一个 JSON 字符串(不是我生成的),其中包含一个带有“。”的字段。并将其转换为 BSON:

Document document = new Document(Document.parse(jsonString));

调用 collection.insertOne() 给我带来了What characters are NOT allowed in MongoDB field names? 中提到的问题。

我现在正在尝试更改文档中包含句点的字段名称。有没有办法遍历文档并更改字段名称?

【问题讨论】:

    标签: java mongodb mongodb-java


    【解决方案1】:

    我会把你指向 db.collection.update(),比如:

    db.collection.update({*your_find_query*},{$rename:{*fields_to_rename*}},{multi:true})
    

    通过设置multi:true,您将更新所有符合查询条件的文档。

    更多信息:http://docs.mongodb.org/manual/reference/method/db.collection.update/

    【讨论】:

      猜你喜欢
      • 2017-05-28
      • 1970-01-01
      • 1970-01-01
      • 2020-05-25
      • 2015-01-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多