如何从我的 mongodb 数据库中删除用户?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/35341670/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
how can I remove user from my mongodb database?
提问by user3766930
I have a database to which I assigned one user that I want to remove right now.
我有一个数据库,我为该数据库分配了一个要立即删除的用户。
My commands looks as follows:
我的命令如下所示:
> show dbs
admin 0.000GB
users 0.000GB
local 0.000GB
> use admin
switched to db admin
> show users
{
"_id" : "admin.root",
"user" : "root",
"db" : "admin",
"roles" : [
{
"role" : "readWriteAnyDatabase",
"db" : "admin"
},
{
"role" : "userAdminAnyDatabase",
"db" : "admin"
},
{
"role" : "dbAdminAnyDatabase",
"db" : "admin"
},
{
"role" : "clusterAdmin",
"db" : "admin"
}
]
}
{
"_id" : "admin.myuser",
"user" : "myuser",
"db" : "admin",
"roles" : [
{
"role" : "root",
"db" : "admin"
}
]
}
And now when I want to remove user myuser
I'm doing the following procedure:
现在,当我想删除用户时,myuser
我正在执行以下过程:
> db.dropUser(myuser)
2016-02-11T14:13:21.107+0000 E QUERY [thread1] ReferenceError: myuser is not defined :
@(shell):1:1
What might be the reason for that and how can I remove this user from my database?
这可能是什么原因,我如何从我的数据库中删除这个用户?
回答by chridam
The db.dropUser()
method accepts a string parameter for username, in your case it's throwing an error because the argument is invalid.
该db.dropUser()
方法接受用户名的字符串参数,在您的情况下,它会抛出错误,因为该参数无效。
Try using a string:
尝试使用字符串:
> use admin
> db.dropUser("myuser")
or run the dropUser
command:
或运行dropUser
命令:
> use admin
> db.runCommand( { dropUser: "myuser" } )