How to remove user in mongodb

Viewed 35

I have two users in mongodb :

{
        "_id" : "admin.mongoAdmin",
        "userId" : UUID("f3000e65"),
        "user" : "mongoAdmin",
        "db" : "admin",
        "roles" : [
                {
                        "role" : "read",
                        "db" : "admin"
                },
                {
                        "role" : "userAdminAnyDatabase",
                        "db" : "admin"
                },
                {
                        "role" : "root",
                        "db" : "admin"
                }
        ],
        "mechanisms" : [
                "SCRAM-SHA-1",
                "SCRAM-SHA-256"
        ]
}
{
        "_id" : "admin.mongoadmin",
        "userId" : UUID("5cf8846e-309f263"),
        "user" : "mongoadmin",
        "db" : "admin",
        "roles" : [
                {
                        "role" : "userAdminAnyDatabase",
                        "db" : "admin"
                },
                {
                        "role" : "dbAdminAnyDatabase",
                        "db" : "admin"
                },
                {
                        "role" : "readWriteAnyDatabase",
                        "db" : "admin"
                }
        ],
        "mechanisms" : [
                "SCRAM-SHA-1",
                "SCRAM-SHA-256"
        ]
}

As you see there are two users:

mongoAdmin and mongoadmin . and I want to remove only "mongoadmin".

How can I remove only "mongoadmin" ?

I wonder if db.dropUser("mongoadmin") may remove the mongoAdmin too because they are the same if we ignore case sensitivity .

1 Answers

Try using the deleteOne method:

db.<CollectionName>.deleteOne( {"userID" : UUID("f3000e65")})
Related