How to Configure MongoDB Atlas Column Level Security

Published
Length
3 min read

Luis Felipe Dias

All posts

You cannot set up native mongodb atlas column level security using standard database roles alone. MongoDB roles only control permissions down to the collection level, not individual document fields. Most teams start by assigning built-in read or write roles to database users. When those roles are too broad, every query returns complete documents with sensitive fields attached. Engineers and analysts then receive raw emails, phone numbers, card numbers, and national IDs. How mongodb atlas colum

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.

You cannot set up native mongodb atlas column level security using standard database roles alone. MongoDB roles only control permissions down to the collection level, not individual document fields. Most teams start by assigning built-in read or write roles to database users. When those roles are too broad, every query returns complete documents with sensitive fields attached. Engineers and analysts then receive raw emails, phone numbers, card numbers, and national IDs.

How mongodb atlas column level security works with native roles

MongoDB uses role-based rules to decide what a user can do inside a database. Each role grants a specific set of actions on a chosen resource. According to the official manual, a role only works down to the collection level. Atlas database users get different built-in roles than self-hosted users, but both share privilege actions.

The built-in read role lets a user read all non-system collections in one database. It allows actions like finding documents, listing collections, listing indexes, and checking collection stats. It also permits database stats and change stream reads on those collections. It blocks users from inserting, updating, removing, or dropping collections.

The read and write role includes every action from the basic read role. It also adds actions to insert, update, and remove documents across collections. Users with this role can create or drop collections and manage collection indexes too. None of these actions let an admin restrict a specific field inside a document.

Because roles stop at the collection boundary, teams often build filtered read-only views. An admin creates a view on top of a source collection and omits secret fields. The admin then grants a user read permissions on the new view only. Other teams split sensitive fields into separate collections with tighter role rules.

What native collection roles solve and what they leave open

Native roles and filtered views solve basic permission problems for fixed apps and reports. They decide who can log in and which collections a user can read or change. If an analyst only needs five safe fields, a custom view works well at first. It keeps the analyst out of the main collection during normal daily work.

Still, this setup leaves a big operational gap for live debugging and support work. Views take extra time to build and maintain as document schemas change over time. Every time an app adds a new field, someone must update the view rules. Splitting data into extra collections also forces developers to rewrite app queries and logic.

Column-Level Encryption + MongoDB Authentication & Authorization: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

More importantly, native roles only check permissions at login and collection selection time. They do not inspect what individual queries or commands do while in flight. When an on-call engineer needs access to a main collection to fix a bug, views fail. The engineer gets full collection read permissions, and every query returns all fields in full.

A role cannot rewrite matched fields in results when a user runs an ad-hoc query. Once a user has collection read rights, raw emails and card numbers flow back. Native permissions also do not require peer approval before someone runs a sensitive read command.

Practical steps to protect sensitive document fields

Start by mapping which collections hold sensitive data like phone numbers and national IDs. Remove broad database-wide read roles from human users and daily support accounts right away. Give each app and team a role scoped only to the collections they truly need.

Next, separate human debug sessions from automated app traffic in your database setup. Do not share one high-privilege login across a whole engineering team for production checks. Pair collection roles with field-level masking that rewrites matched fields in results before data arrives.

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

Does MongoDB Atlas support column level permissions in built-in roles?

No, MongoDB roles only grant access down to the collection level of granularity. A role allows actions like find or update on a whole collection, not single fields.

What is the difference between the read and readWrite roles in MongoDB?

The read role lets users find documents, list collections, check stats, and read change streams. The readWrite role adds actions to insert, update, remove documents, and create or drop collections.

How can teams hide sensitive fields during live database queries?

Teams can create filtered collection views or apply dynamic data masking to query traffic. Data masking rewrites matched fields like emails, phone numbers, and card numbers in query results.

The query runs. The emails stay hidden.