1

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

{
"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 ,但它似乎甚至没有将自己添加到数组中。

{$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。

4

1 回答 1

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"}}
}

这称为点表示法。真的很有用。

于 2013-10-03T13:17:10.600 回答