1

I've been trying to get certain elements into this code. (Please ignore the silly dummy data)

{
"Order_Number": "1",
"Status": "Pending",
"Customer":{
    "First_Name": "Juan",
    "Second_Name": "De La Cruz",
    "Email": "[email protected]",
    "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"
            }
        ]
    }
}
}

Now , I've been trying to get these elements into "Shipping Transactions".

{

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

I've tried doing push , but it doesn't even seem to add itself to the array.

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

Might this code have a flaw or am I doing something wrong ? I'm only using MongoDb's web shell btw.

1 Answer 1

2

This should do it:

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

It's called dot notation. Really useful.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.