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?
To list existing users in MongoDB, you can use the db. getUsers() method to show all of the users within the current database.
For users created in MongoDB, MongoDB stores all user information, including name , password , and the user's authentication database , in the system. users collection in the admin database. Do not modify this collection directly. To manage users, use the designated user management commands.
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" } )
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With