'How to remove a user from a MongoDB database
I have a database to which I assigned one user that I want to remove right now.
My commands looks like:
> 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"
}
]
}
When I want to remove user myuser I'm using:
> db.dropUser(myuser)
2016-02-11T14:13:21.107+0000 E QUERY [thread1] ReferenceError: myuser is not defined :
@(shell):1:1
What is the reason for that and how can I remove this user from my database?
Solution 1:[1]
The db.dropUser() method accepts a string parameter for username, in your case it's throwing an error because the argument is invalid.
Try using a string:
> use admin
> db.dropUser("myuser")
or run the dropUser command:
> use admin
> db.runCommand( { dropUser: "myuser" } )
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | chridam |
