无法将对象插入Mongodb中的对象数组中

时间:2013-10-03 13:14:24

标签: arrays mongodb push

我一直在尝试将某些元素放入此代码中。 (请忽略愚蠢的虚拟数据)

{
"Order_Number": "1",
"Status": "Pending",
"Customer":{
    "First_Name": "Juan",
    "Second_Name": "De La Cruz",
    "Email": "juandelacruz@gmail.com",
    "contact": "0923275937"
           },
"Shipping_Address": "291,Ominous Building, Quezon City, Philippines",
"Billing_Address": "IOU, Iowa, USA",
"Weight": "200 lbs.",
"Description": "Joots",
"Tracking Information": {
    "Tracking Number": "000000001",
    "Shipping History": {
        "Shipping Transactions": [
            {
                "Date Received": "10/1/2013",
                "Date Released": "10/10/2013",
                "Source": "Center of the earth",
                "Control Number": "100010001"
            },
            {
                "Date Received": "10/2/2013",
                "Date Released": "10/12/2013",
                "Source": "Center of Venus",
                "Control Number": "100010002"
            },
            {
                "Date Received": "10/3/2013",
                "Date Released": "10/13/2013",
                "Source": "San Francisco",
                "Control Number": "100010003"
            }
        ]
    }
}
}

现在,我一直在努力将这些元素纳入“运输交易”。

{

        "Date Received": "10/2/2013",
        "Date Released": "10/11/2013",
        "Source": "Center of Mars",
        "Control Number": "100010005"
}

我尝试过推送,但它似乎甚至没有将自己添加到数组中。

{$push:{"Tracking Information":{"Shipping History":{"Shipping Transactions":
   [{"Date Received": "10/4/2013",
    "Date Released": "10/11/2013",
    "Source": "Center of Mars",
    "Control Number": "100010005"}]
 }

这个代码可能有缺陷还是我做错了什么?我只使用MongoDb的web shell btw。

1 个答案:

答案 0 :(得分:2)

这应该这样做:

{
  $push:{"Tracking Information.Shipping History.Shipping Transactions": {"Date Received": "10/4/2013",
    "Date Released": "10/11/2013",
    "Source": "Center of Mars",
    "Control Number": "100010005"}}
}

它被称为dot notation。真有用。