MongoDB Grant Permissions to User

Published
Length
3 min read

Luis Felipe Dias

All posts

To handle a mongodb grant permissions to user request, admins assign roles on a database. Each role combines specific actions with target resources down to the collection level. Teams use these role assignments to control what engineers and apps can do. A user only runs commands that match their assigned role privileges. How a mongodb grant permissions to user workflow runs in practice MongoDB uses role-based rules to control database access. A role grants privileges to run sets of actions o

Your coding agents run with your access.

Claude Code reaches prod with a developer's credentials, and approval prompts get clicked through. hoop.dev checks every query, masks sensitive data, and holds risky changes for a human.

To handle a mongodb grant permissions to user request, admins assign roles on a database. Each role combines specific actions with target resources down to the collection level.

Teams use these role assignments to control what engineers and apps can do. A user only runs commands that match their assigned role privileges.

How a mongodb grant permissions to user workflow runs in practice

MongoDB uses role-based rules to control database access. A role grants privileges to run sets of actions on defined resources. The role applies to the database where an admin defines it. It can grant access down to the collection level.

MongoDB Atlas database users have different built-in roles than self-hosted users. Still, both types build on the same set of privilege actions. Admins pick between two common built-in roles for daily work.

The read role gives read access to all non-system collections in its database. It also covers the system JavaScript collection. This role permits actions like finding documents and listing collections or indexes. It also allows checking database stats, collection stats, and change streams. It blocks actions that insert, update, remove, or drop collections.

The read and write role includes every action from the read role. It adds the power to change data across the database. Allowed actions include inserting, updating, and removing documents. Users can also create collections, build indexes, drop indexes, and drop collections.

Engineers and AI agents log in and inherit these role boundaries right away. When an agent runs a query, the database checks the assigned role first. If the action matches the resource rule, the database returns the result.

User Provisioning (SCIM) + MongoDB Authentication & Authorization: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

Security tradeoffs of static roles and collection permissions

Role rules stop unauthorized writes, but they leave gaps during active sessions. First, built-in roles stop at the collection level. A user with read rights on a collection can read every field inside it. If a document holds emails, phone numbers, card numbers, or national IDs, queries return them.

Second, static user accounts create long-term key management work for platform teams. Engineers and AI tools often keep database keys in local files. If a key leaks, an attacker gets full role access right away. Admins must rotate keys and update roles across clusters by hand.

Third, broad roles make it hard to check individual commands before they run. A read and write role lets an engineer fix one broken record. The same role also lets them drop a whole collection by mistake. Role checks alone cannot ask a peer to approve one risky command.

To reduce these risks, teams pair database roles with query-level controls. Data masking rewrites matched fields like emails or card numbers in query results. Command reviews pause destructive writes until a teammate approves the action. Identity checks tie every query to a single person instead of a shared role.

Inspect MongoDB wire traffic in flight

Built-in MongoDB roles govern collection access at setup time. They cannot score command risk per call or mask sensitive document values on the fly. By design, hoop.dev sits inline in the MongoDB protocol next to your server as a sidecar for your MongoDB. On every production command from mongosh, drivers, or AI agents, hoop.dev decides whether to pass, mask, block, or hold it for human review.

First, hoop.dev guardrails block bad deletes, drops, and write pipelines or hold them for approval. Next, hoop.dev data masking rewrites sensitive values in returned documents in memory and logs each decision. Explore the repo on GitHub.

Frequently asked questions

What is the lowest level of access a MongoDB role can grant?

A role applies to the database where an admin defines it. Within that database, a role can grant access down to the collection level. Native roles do not restrict specific fields inside a document on their own.

What is the difference between the read and readWrite roles?

The read role lets users find data, list collections, list indexes, and check stats. It blocks data changes. The readWrite role adds actions to insert, update, and remove data, or drop collections.

Do MongoDB Atlas and self-hosted databases use the exact same roles?

No, MongoDB Atlas database users have different built-in roles than self-hosted database users. Still, both setups build their roles from the same core set of privilege actions.

The query runs. The emails stay hidden.