MongoDB — Users
Create User
use mydb
db.createUser({
user: "john",
pwd: "password",
roles: ["readWrite"]
})
List Users
db.getUsers()
Update User
db.updateUser("john", {
roles: ["readWrite", "dbAdmin"]
})
Change Password
db.changeUserPassword("john", "newpassword")
Drop User
db.dropUser("john")
Roles
| Role | Description |
|---|---|
| read | Read only |
| readWrite | Read and write |
| dbAdmin | Database admin |
| userAdmin | Manage users |
| root | Full access |
Mini Practice
- Create a user
- List all users
- Update user roles
- Drop a user
Up Next
Continue with Backup — backup and recovery.
Related Topics
Frequently Asked Questions about Users
What is Users in MongoDB?
Users is a fundamental concept in MongoDB. This lesson explains it step by step with clear examples, making it easy for beginners to understand.
How do I learn Users?
Start by reading the explanation above, then try the code examples. Practice by modifying the examples and experimenting with different values. Hands-on practice is the best way to learn Users.
Why is Users important in MongoDB?
Users is essential for MongoDB development. Understanding this concept will help you write better code and solve real-world problems more effectively.