Mongodb Drop User

By Yashwant Chavan, Views 1317, Date 09-Oct-2016

In this tutorial we will learn how to drop user from the current database using db.dropUser() method.

tags mongodb

mongoDB Drop User - db.dropUser()

Removes / Drop the user from the current database. Refer following dropUser() method syntax.

db.dropUser(username, writeConcern)

username - string type parameter, Provide name of the user which you want to remove from the database.

writeConcern - Optional document parameter , Introduce in version 2.6. It describe level of acknowledgement requested from MongoDB while performing write / create operations to a standalone mongoDB, replica sets, sharded clusters.

> db.dropUser("scott", {w: "majority", wtimeout: 5000})

In this example, user scott is dropped / removed from the technicalkeeda database. db.getUsers() method is used to display all the users associated with current database.

> db.getUsers()
[
        {
                "_id" : "technicalkeeda.scott",
                "user" : "scott",
                "db" : "technicalkeeda",
                "customData" : {
                        "employeeId" : 999,
                        "employeeName" : "Yashwant Chavan",
                        "dept" : "Information Technology"
                },
                "roles" : [
                        {
                                "role" : "readWrite",
                                "db" : "technicalkeeda"
                        },
                        {
                                "role" : "dbAdmin",
                                "db" : "technicalkeeda"
                        }
                ]
        }
]
> db.dropUser("scott", {w: "majority", wtimeout: 5000})
true
> db.getUsers()
[ ]
Yashwant Chavan

Yashwant Chavan

Hi there! I am founder of technicalkeeda.com and programming enthusiast. My skills includes Java,J2EE, Spring Framework, Nodejs, PHP and lot more. If you have any idea that you would want me to develop? Lets connect: yashwantchavan@gmail.com