How can I remove a user from my mongodb database?

I have a database to which I have assigned one user that I want to delete right now.

My commands are 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 delete the user myuser, I do the following procedure:

> db.dropUser(myuser)
2016-02-11T14:13:21.107+0000 E QUERY    [thread1] ReferenceError: myuser is not defined :
@(shell):1:1

What could be the reason for this and how can I remove this user from my database?

+4
source share
1 answer

The method accepts a string parameter for the username; in your case, it throws an error because the argument is invalid. db.dropUser()

Try using the line:

> use admin
> db.dropUser("myuser")

or run the command : dropUser

> use admin
> db.runCommand( { dropUser: "myuser" } )
+12
source

Source: https://habr.com/ru/post/1628320/


All Articles