How to Configure Haystack MongoDB Read Only Access
You set up haystack mongodb read only access by giving a database user the read role. Then you pass that user key to your Haystack document store component. Teams often start by reusing a broad admin user during early testing. That shortcut gives the pipeline power to change or delete live data. If a prompt injection or code bug occurs, your records face real risk. A dedicated read user blocks write actions before they start. How haystack mongodb read only access works with database roles Mon
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 haystack mongodb read only access by giving a database user the read role. Then you pass that user key to your Haystack document store component. Teams often start by reusing a broad admin user during early testing. That shortcut gives the pipeline power to change or delete live data. If a prompt injection or code bug occurs, your records face real risk. A dedicated read user blocks write actions before they start.
How haystack mongodb read only access works with database roles
MongoDB controls user permissions through role-based rules. A role gives a user the right to run actions on set resources. Each role applies to the database where you define it. You can also scope custom roles down to a single collection. Note that MongoDB Atlas users have different built-in roles than self-hosted users. Still, both systems build their roles from the same core privilege actions.
For retrieval pipelines, the built-in read role is the standard starting point. The read role lets the user read all non-system collections in that database. It allows actions like finding records, listing collections, and checking index stats. It also permits opening a change stream and reading one specific system collection. The role leaves out actions that insert, update, or remove documents. It also blocks the user from dropping a collection or changing indexes.
In contrast, the read-write role includes every read action plus data changes. It lets a user insert, update, and remove documents across the database. It also allows creating or dropping collections and indexes. When your Haystack pipeline only fetches context for a model, it never needs write rights. You create a database user with the read role on your target database. Then you store those login details in your app secret store. Your Haystack retriever uses that login to run search queries without write risk.
What native roles solve and what they leave open
Native database roles solve a major part of the data safety problem. They stop a retrieval app from altering or deleting your stored documents. Once the user logs in, the database engine blocks any write command. This setup protects data integrity if an app component acts in an unexpected way. It also helps teams separate data loading jobs from live search apps. Your indexing job can use a write role on a set schedule. Meanwhile, your live Haystack query pipeline runs with read rights all day.
Auditor Read-Only Access + Customer Support Access to Production: architecture patterns and best practices
Continue reading? Get the full guide.
Free. No spam. Unsubscribe anytime.
Still, database roles only decide who can log in and which collections they read. They do not inspect what individual queries return in flight. A read role grants access to every field inside a permitted collection. If a document holds emails, phone numbers, card numbers, or national IDs, the query pulls them all. The database sends the full record back to the Haystack pipeline. From there, raw personal data can flow straight into a model prompt.
Collection-level roles cannot filter out sensitive fields inside a document on the fly. Teams often try to fix this by building clean copy collections. Maintaining extra pipelines and duplicate storage adds high cost and daily work. You also lack a clear log tied to the person or service behind each query. Native roles verify the shared app login at the door. They do not track or rewrite field data inside individual query results.
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 is an open-source proxy that sits next to MongoDB as a sidecar for your MongoDB. It reads every command from mongosh, drivers, or agent tools.
First, hoop.dev guardrails block bad deletes, drops, and write pipelines. Next, hoop.dev data masking rewrites sensitive values in returned documents based on your rules and logs each decision. Explore the repo on GitHub.
Frequently asked questions
What is the difference between the MongoDB read and readWrite roles?
The read role allows finding data and viewing collection or index stats. It blocks adding, changing, or deleting records and dropping collections. The read-write role adds rights to insert, update, remove, and manage collections.
Can I limit a Haystack database user to one MongoDB collection?
Yes, MongoDB roles can grant access down to the collection level. While the built-in read role covers all non-system collections, you can define a custom role. That custom role can restrict find actions to the single collection Haystack uses.
Does a read-only database role protect sensitive fields from language models?
No, a read role allows the user to read the entire document in a collection. If records contain emails, phone numbers, or card numbers, the query returns those fields. You need field-level masking to rewrite matched fields in results before they reach the model.
Related guides
In this post