MongoDB Drop All Users

By Yashwant Chavan, Views 2612, Last updated on 01-Mar-2019

In this tutorial, we will learn how to drop all the users from the current database using db.dropAllUsers() method.

tags mongodb

mongoDB Drop All Users - db.dropAllUsers()

Drop / Remove all the users from the current database. Refer following dropAllUsers() method syntax.


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.dropAllUsers( {w: "majority", wtimeout: 5000} )

In this example, I have created two users "yashwant" and "dinesh" for the database ("technicalkeeda"), db.dropAllUsers() method drop all the users from the current database.

> use technicalkeeda
switched to db technicalkeeda

> db.createUser({user: "yashwant",pwd: "chavan",roles: []})
Successfully added user: { "user" : "yashwant", "roles" : [ ] }

> db.createUser({user: "dinesh",pwd: "patil",roles: []})
Successfully added user: { "user" : "dinesh", "roles" : [ ] }

> db.getUsers()
                "_id" : "technicalkeeda.dinesh",
                "user" : "dinesh",
                "db" : "technicalkeeda",
                "roles" : [ ]
                "_id" : "technicalkeeda.yashwant",
                "user" : "yashwant",
                "db" : "technicalkeeda",
                "roles" : [ ]

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

The NumberLong(2) shows the number of users dropped / removed from the database.



Hi there! I am founder of 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[at][]