我有以下集合,如下所示: -
{
"_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}});