Alexander Tilkin
Alexander Tilkin

Reputation: 319

Remove subdocument from document

I would like to remove the Path object from the document. I tried to use the $unset operator but it demands value which I don't have to give. Is there a way to remove a whole sub document from document?

{
    "Address" : {
        "Country" : "temp",
        "City" : "temp",
        "Street" : "temp",
        "House" : "temp",
        "Apartment" : "temp"
    },
    "Birthday" : {
        "Date" : {
            "Day" : "temp",
            "Moth" : "temp",
            "Year" : "temp"
        }
    },
    "ConnectionStatus" : "Offline",
    "DisplayName" : "temp",
    "Email" : "temp",
    "FirstName" : "temp",
    "LastName" : "temp",
    "Password" : "temp",
    "Path" : {
        "Start" : {
            "Longtitude" : 400,
            "Latitude" : 300
        },
        "End" : {
            "Longtitude" : 500,
            "Latitude" : 400
        },
        "Milestones" : [ 
            {
                "Longtitude" : 420,
                "Latitude" : 320
            }, 
            {
                "Longtitude" : 450,
                "Latitude" : 350
            }, 
            {
                "Longtitude" : 480,
                "Latitude" : 380
            }
        ]
    },
    "ProgressStatus" : "Safe",
    "_id" : ObjectId("5201cadc5b4da1f65a000001")
}}

Upvotes: 0

Views: 89

Answers (1)

Ori Dar
Ori Dar

Reputation: 19000

db.coll.update({"_id" : ObjectId("5201cadc5b4da1f65a000001")}, {$unset: {Path : 1}})

You have to give the $unset operator a value of 1

Replace coll with your collection name

Upvotes: 1

Related Questions