如何删除mongo集合中任何值的键?

时间:2018-04-04 12:10:36

标签: mongodb

我有以下集合,如下所示: -

{
    "_id" : ObjectId("5aba0f8fd19bc9314089a9ba"),
    "repoha" : [ ],
    "name" : "myrep2",
    "repo_number" : 4,
    "store_front_port" : null,
    "old_repo_paths" : [
        {
            "path" : "/opt/immune/storage/",
            "retention" : 2
        },
        {
            "path" : "/secondarytier/",
            "retention" : 10
        },
        {
            "path" : "/teritarydir/dir1/",
            "retention" : 3
        }
    ],
    "repopath" : [
        {
            "path" : "/opt/immune/storage/",
            "retention" : 2
        },
        {
            "path" : "/teritarydir/dir1/",
            "retention" : 3
        }
    ],
    "tid" : "",
    "used_size" : "0.00781 MB",
}

如何删除名为" old_repo_paths"的密钥并且具有任何值,以便集合看起来像

{
    "_id" : ObjectId("5aba0f8fd19bc9314089a9ba"),
    "repoha" : [ ],
    "name" : "myrep2",
    "repopath" : [
        {
            "path" : "/opt/immune/storage/",
            "retention" : 2
        },
        {
            "path" : "/teritarydir/dir1/",
            "retention" : 3
        }
    ],
    "tid" : "",
    "used_size" : "0.00781 MB",
}

我尝试了未设置的方法,但却遇到了错误 db.repo.update({_id:ObjectId("5aba0f8fd19bc9314089a9ba")},{$unset: {old_repo_paths}});

0 个答案:

没有答案