mongoDB – user admin cheat sheet

Connect with

MongoDB User admin cheat sheet
This article explains about MongoDB user admin cheat sheet for performing MongoDB user admin roles. Different activities and their commands to manage user management activities in MongoDB.
I have not mentioned all the activities command but try to mention which admin use very frequently.

1. Overview of MongoDB user admin cheat Sheet

In this mongodb user admin cheat sheet, I tried to collect all the commands and their activities for your MongoDB user admin role.

Well, you can do different activities as a MongoDB user admin for that you have to learn, but don’t worry about learning, you can go to this article carefully for your learning.

There are diffent cheat sheet of mongoDB on mysoftkey.com as follows:

2. How to logged-in into mongos using auth ?

On terminal run the following command to connect mongodb client to access the database.

mongo --port 27017 -u "username" -p "xxxxx" --authenticationDatabase "admin"

OR

mongo
> db.auth('username','xxxxx');

3. How to graceful shutdown of mongo Node?

Folloing command is used for shutting down the database gracefully. This command will not impact of database specially server is in replicaset.

> use admin;
> db.shutdownServer();

3. How to add mongodb user?

Following command used for creating a user in a perticular database.

db.createUser({user: "coreuser", pwd: "123#x234", roles:[ { role: "readWrite", db: "orderDB" }, { role: "dbOwner", db: "orderDB" }, {role: "readAnyDatabase",db:"admin"}] });

5. How to change password of mongodb user ?

For mongoDB user admin , following command is used for changing password of a provided user in MongoDB. here database can be admin or any another but mostly we do in admin database. You can run this command in which database you have created .

> db.changeUserPassword("orderDB", "orde@12345%%");

6. How to grant role to user in mongodb ?

Following command is used for granting of role to a user in MongoDB admin database , which has been selected if not please use admin before running this command.

> db.grantRolesToUser("ranjeet",[{role: "readWriteAnyDatabase", db:"admin"}])

7. How to drop mongodb user ?

Following command is used for dropping a user in MongoDB for selected database. Here, database can be admin or any another but mostly we do in admin database by MongoDB user admin.

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

OR

> db.dropUser("orderDBUser")

8. Reference

You can visit docs.mongodb.com for more details.

Thanks for visiting this post for MongoDB config replica set. You can also visit MongoDB Tutorial Listing page for more articles on MongoDB document-oriented database.
Happy Learning 🙂 for MongoDB replica set config.
Your comments are welcome to improve this post. happy learning 🙂


Connect with