How to Remove User From Database in MongoDB

MD Aminul Islam Feb 02, 2024
How to Remove User From Database in MongoDB

This article will introduce how we can remove a user from the MongoDB database. Also, we will see an example to make the topic easier.

Remove a User From MongoDB Database

Sometimes we need to remove a specific user from the MongoDB database for numerous purposes. If you are using the MongoDB console, there is a command named removeUser(), which is used to remove a user from MongoDB.

Now, this function takes a string as a parameter, and the general syntax for this command is below.

db.removeUser(USER_NAME)

Please note that if you are using MongoDB version 2.6 or more, you have to use db.dropUser() instead of db.removeUser(). The syntax will remain the same.

In our example below, we will illustrate how we can remove a user from the MongoDB database. The command will be as follows:

db.removeUser("User1")

When you run the above command, it will remove User1 from your MongoDB database.

Please note that you must provide the username as a string in the function removeUser(). Otherwise, it will show an error.

Please note that the commands shown in this article are for the MongoDB database and the command needs to be run on the MongoDB console.

MD Aminul Islam avatar MD Aminul Islam avatar

Aminul Is an Expert Technical Writer and Full-Stack Developer. He has hands-on working experience on numerous Developer Platforms and SAAS startups. He is highly skilled in numerous Programming languages and Frameworks. He can write professional technical articles like Reviews, Programming, Documentation, SOP, User manual, Whitepaper, etc.

LinkedIn

Related Article - MongoDB User