Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how can I remove user from my mongodb database?

Tags:

mongodb

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?

like image 556
user3766930 Avatar asked Feb 11 '16 14:02

user3766930


People also ask

How do I see all users in MongoDB?

To list existing users in MongoDB, you can use the db. getUsers() method to show all of the users within the current database.

Where are MongoDB users stored?

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.


1 Answers

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" } )
like image 128
chridam Avatar answered Oct 11 '22 14:10

chridam