mongoDB – user admin cheat sheet

Connect with

MongoDB User admin cheat sheet
This Post is about how to do user management activities in mongodb.

Well, you can do different activity as user admin of mongodb that you have to learn , but you don’t worrry about learning.

There are diffent cheat sheet of mongoDB on as follows:

how to logged-in into mongos using auth ?

on terminal run the following command

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


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

How to graceful shutdown of mongo Node?

> use admin;
> db.shutdownServer();

How to add mongodb user?

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

How to change password of mongodb user ?

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

How to grant role to user in mongodb ?

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

How to drop mongodb user ?

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


> db.dropUser("orderDBUser")

Your comments are welcome to improve this post. happy learning 🙂

Connect with

Leave a Reply

Your email address will not be published. Required fields are marked *