How to Configure MongoDB Backup User

Published
Length
3 min read

Luis Felipe Dias

All posts

You set up a mongodb backup user by assigning a role that grants read actions on target databases. You must avoid granting write actions or admin privileges to this account. Many teams rush this setup and attach broad admin roles to their backup scripts. When a backup account has write access, a bug or stolen key can delete production data. Scoping the account to read-only actions prevents accidental changes during scheduled exports. How to set up a mongodb backup user MongoDB controls access

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 set up a mongodb backup user by assigning a role that grants read actions on target databases. You must avoid granting write actions or admin privileges to this account. Many teams rush this setup and attach broad admin roles to their backup scripts. When a backup account has write access, a bug or stolen key can delete production data. Scoping the account to read-only actions prevents accidental changes during scheduled exports.

How to set up a mongodb backup user

MongoDB controls access through role-based rules. Each role grants specific actions on defined resources. A role applies to the database where you create it. It can grant permissions down to a single collection. Note that MongoDB Atlas and self-hosted setups have different built-in roles. Still, both systems build their roles from the same underlying privilege actions.

For a single database export, the built-in read role often works well. It lets the user read all non-system collections and the system JavaScript collection. It grants actions like finding documents, listing collections, listing indexes, and checking stats. It leaves out actions that change data, such as insert, update, remove, or drop collection.

When your backup job spans the whole cluster, you create the user in the admin database. You then assign a built-in backup role or a custom role with cluster-wide read actions. You should pair this role with strong credentials and network rules. Always store the user key in a safe secret store rather than in plain text scripts.

Why native backup roles leave an operational gap

Native database roles solve the first step of access control. They check who logs in and which collections that account can read. Once the session starts, Still, native roles do not inspect individual queries in flight. A role cannot tell if a request comes from a nightly job or an engineer running manual exports.

Because a backup role reads every document, it pulls all fields by default. That includes emails, phone numbers, card numbers, and national IDs. If an engineer uses the mongodb backup user credentials to debug an issue, raw sensitive fields leave the server. Native roles also stop at the collection boundary. They do not rewrite matched fields in query results or ask for peer review before large dumps.

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

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

Managing human and automated read sessions

To reduce risk, teams should separate automated backup accounts from human read accounts. Automated scripts need full raw data to restore a database later. Human users running ad-hoc checks or data exports rarely need raw personal data. Giving humans the backup login breaks audit trails because many people share one static key.

Instead, link human database sessions to individual work identities. When someone runs a query, the system should log their identity along with the exact command. Adding data masking in the path rewrites matched fields like emails and card numbers in results. This keeps production exports safe for testing while keeping raw backups locked away.

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 difference between the read and readWrite roles in MongoDB?

The read role lets a user find data, list collections, and check stats without changing records. The readWrite role adds actions that change data, like insert, update, remove, and drop collection.

How fine-grained are MongoDB role permissions?

A MongoDB role applies to the database where it is defined. It can grant privilege actions on an entire database or down to the collection level.

Why should engineers not share the mongodb backup user for debugging?

Sharing a backup account hides who ran which query in the logs. It also exposes raw emails, phone numbers, and card numbers during routine checks.

The query runs. The emails stay hidden.