从文档中删除子文档

时间:2013-08-07 06:01:08

标签: mongodb nosql

我想从文档中删除 Path 对象。 我尝试使用 $ unset 运算符,但它需要,我不必提供。 有没有办法从文档中删除整个子文档?

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

1 个答案:

答案 0 :(得分:1)

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

您必须为 $ unset 运算符赋值 1

coll替换为您的收藏名称