0

我需要通过将投标插入投标数组中来更新文档,投标数组是投标的一部分。示例文档如下:

{
  "_id" : "1044300051",
  "Bids" : {
    "Bid" : [
        {
            "Bidder" : {
                "_id" : "pickford25",
                "_Rating" : 255,
                "Location" : "ANIME PARADISE",
                "Country" : "USA"
            },
            "Time" : "Dec-07-01 15:02:54",
            "Amount" : 1.12
        },
        {
            "Bidder" : {
                "_id" : "arlnwtkwsk@aol.com",
                "_Rating" : 61,
                "Location" : "ARCADE, NEW YORK",
                "Country" : "USA"
            },
            "Time" : "Dec-09-01 15:02:54",
            "Amount" : 1.25
        }
    ]
  }
}

以下是我尝试过的一些查询:

db.items.update({_id: "1678348584"}, {$set: {Bids: "Bid[]"}},{$push: {"Bids.Bid": {"Amount":1000}}});
db.items.update({_id: "1678348584"}, {$push: {"Bids": [{"Amount":1000}]}});

我在上述示例中尝试更新的特定 _id 最初将“Bids”设置为 null

4

1 回答 1

1

你快到了。要访问嵌套数组,您必须使用Bids.Bid. 您的查询应该类似于

db.items.update({_id: "1678348584"}, {$push: {"Bids.Bid": {"Amount":1000}}});
于 2018-04-19T19:49:34.900 回答