【问题标题】:How to update mongodb collection if there is no primary key如果没有主键,如何更新 mongodb 集合
【发布时间】:2019-04-25 06:35:31
【问题描述】:

我有一个集合,在那个集合中没有主键 id 但有 _id。如何向集合中添加一个字段作为主键 ID

【问题讨论】:

  • 您能否通过更新问题以显示您正在寻找的具体示例来澄清您的问题?
  • 您好,文档中的 _id 字段是 MongoDB 中每个缺陷的主键。如果您需要更新一个或多个文档,您可以使用 db.collection.update docs.mongodb.com/manual/reference/method/db.collection.update/… 只需要您定义一个查询来过滤并使用新值定义 json。

标签: mongodb


【解决方案1】:

_id 是 mongodb 中的主节点。另见Difference between “id” and “_id” fields in MongoDB

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-11-26
    • 2011-04-27
    • 2014-10-13
    • 2021-03-23
    • 1970-01-01
    • 2021-07-14
    • 2014-09-25
    • 2014-03-31
    相关资源
    最近更新 更多