简体   繁体   English

MongoDB扩展嵌入式文档

[英]MongoDB extend Embedded Documents

I have a mongo document as follows: 我有一个mongo文档,如下所示:

{
  _id: ... ,
  field_1: ...,
  field_2: ...,
  changes:{
    "1474607149339":"a7hhs",
    "1474607149463":"98nhs",
    "1474607149657":"cxskk9",
    "1474607149880":"csdda3",
    "1474607151575":"bfddrd",
    "1474607153389":"54fbbb",
  }
}

The big numbers in the changes are timestamp values. changes中的大数字是时间戳记值。 (this is to track history of certain fields in my application). (这是跟踪我的应用程序中某些字段的历史记录)。 I'm sending this changes as small chunks containing few similar entries eg: 我将这些更改作为小块发送,其中包含一些类似的条目,例如:

{
        "1474607159708":"zcdgv",
        "1474607159932":"4h7kk",
        "1474607165362":"nbmnn"
}

how can I extend the changes field in the mongo document to include new changes in a single query (large number of changes need to be recoreded)? 如何在mongo文档中扩展changes字段以在单个查询中包含新更改(需要重新记录大量更改)?

You should be able to insert fields into existing documents using the $set operator: https://docs.mongodb.com/manual/reference/operator/update/set/ 您应该可以使用$set运算符将字段插入现有文档中: https : //docs.mongodb.com/manual/reference/operator/update/set/

db.products.update(
   { _id: 100 },
   { $set: { 
              "changes.1474607159708": "zcdgv",
              "changes.1474607159932": "4h7kk",
              ....
           } 
   }
)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM