Video Transcript (English)
Welcome back. In this video, you will learn how to use the Atlas UI and the Atlas CLI to create and manage database users for your deployment. You’ll also learn how to control the level of access of those users to the MongoDB database.
Before we discuss user management in MongoDB, it’s important to distinguish between database users and Atlas users.
A database user can access MongoDB databases, while an Atlas user can access the Atlas application itself.
In other words, when you create an Atlas account, you are an Atlas user. It’s only when you’re given a role with permissions on a specific database that you are a database user and can interact with data in that database.
For database users, MongoDB provides role-based access rules. These control which users can perform read and write operations on a database.
We create database users to give clients access to specific database deployments in projects. We can even create database users for a database that doesn’t exist yet.
Setting roles and permissions for users adds a crucial layer of security for deployments.
Now, let’s create a database user that has access only to the accounts collection in the sample_analytics database.
First, we click here to edit database access.
Here’s a list of current database users. When we deploy a cluster for the first time, we’re prompted to create the first admin user and give it the `atlasAdmin` role. This role has a number of inherited roles and privileges, including the ability to create a new database user. You should see the first admin user that you created here.
We’ll create a new database user called test-user.
First, we enter a username and password, and then we add specific privileges.
We’ll give this database user a readWrite role on the accounts collection in the sample_analytics database. This means that test_user will be able to perform specific actions like finding, updating, and removing documents on only this collection.
Next, we’ll click Add User.
The new user is on the database access list.
We can also create a new database user by using the Atlas CLI.
We’re already connected to the same project and cluster, so we can use the `atlas dbusers create` command and specify the username, which is test-user-2, the password, and the role. We’ll set the role to readWrite on the accounts collection in the sample_analytics database.
The output shows that the user was successfully created!
Once our new users authenticate, they will be able to use their read and write privileges only on the accounts collection in the sample_analytics database.
Let’s recap what you learned in this video: MongoDB provides role-based access rules to control which users can perform read and write operations on a database.
A database user can access MongoDB databases, while an Atlas user can access the Atlas application itself.
We can use the Atlas UI to create database users on databases and collections and give them specific roles and permissions.
We can use the Atlas CLI to accomplish the same thing by running the `atlas dbusers create` command.
