How to Configure Haystack MongoDB Credentials
You set up haystack mongodb credentials by creating a database user and passing its login details to your document store. This setup links your AI pipeline to your data collections. Teams often start by reusing a broad admin user to get pipelines running fast. Still, wide permissions let a pipeline change or delete whole collections by mistake. Scoping the database user down to specific actions keeps your stored data safe. How to set up haystack mongodb credentials with roles MongoDB controls
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 credentials by creating a database user and passing its login details to your document store. This setup links your AI pipeline to your data collections. Teams often start by reusing a broad admin user to get pipelines running fast. Still, wide permissions let a pipeline change or delete whole collections by mistake. Scoping the database user down to specific actions keeps your stored data safe.
How to set up haystack mongodb credentials with roles
MongoDB controls access through role-based authorization. Each role grants a set of actions on defined database resources. A role applies to the database where you define it. You can also scope access down to a single collection. Note that MongoDB Atlas users have different built-in roles than self-hosted users. Still, both systems build roles from the same basic privilege actions.
Your choice of role depends on what the Haystack pipeline does. A pipeline that only fetches documents needs the built-in read role. The read role grants access to all non-system collections in that database. It allows actions like find, listCollections, listIndexes, dbStats, collStats, and changeStream. It blocks insert, update, remove, and dropCollection actions.
Indexing pipelines that write new embeddings need the readWrite role instead. The readWrite role includes every action in the read role plus data changes. It adds insert, update, remove, createCollection, createIndex, dropIndex, and dropCollection. After you create the user, you store the login string in your secret store. Your Haystack app reads this secret at startup to log in.
What native roles solve and where gaps remain
Native database roles solve the problem of who can log in. They also separate indexing jobs from search jobs. If a search pipeline only has the read role, it cannot drop a collection. This setup stops accidental writes and deletes from happening during search runs.
Yet native roles only check permissions at the database or collection level. Once a user has the read role, it can read every field in that collection. A search pipeline can pull sensitive fields alongside public text. Those records might hold emails, phone numbers, card numbers, or national IDs. Native collection roles do not rewrite matched fields in results before they reach the model.
Ephemeral Credentials + MongoDB Authentication & Authorization: architecture patterns and best practices
Continue reading? Get the full guide.
Free. No spam. Unsubscribe anytime.
Static login strings also create management work for your team. Every pipeline container holds a secret that grants direct access to the database. If an app needs readWrite access to add documents, it also gets dropCollection rights. Native roles decide who logs in, not what each query does in flight.
Scoping permissions to the collection level
You can shrink the blast radius by scoping roles to single collections. Instead of granting read access to a whole database, target only the document collection. This keeps the Haystack pipeline away from user accounts or billing tables in the same database.
Teams should also split indexing pipelines from query pipelines in production. Give the indexing job its own user with write rights on the target collection. Give the query job a separate user with only read rights. This split ensures that user prompts cannot trigger data writes or deletes.
Add command guardrails and field masking beside MongoDB
Collection roles and IP rules control who connects to MongoDB. Yet an active client or agent session can still run a pipeline that writes data or reads raw personal fields. In practice, hoop.dev runs beside your database as a sidecar for your MongoDB. It checks every wire command and result document without changing your drivers or credentials.
Using hoop.dev MongoDB controls, guardrails refuse banned commands before they run. Data masking rewrites matched fields in returned documents in memory. Furthermore, hoop.dev holds SOC 2 Type II, is MIT licensed, and generates evidence for GDPR, HIPAA, and PCI DSS programs. View the project on GitHub.
Frequently asked questions
Which database role should a Haystack search pipeline use?
Use the built-in read role scoped to your specific document collection. It allows find and index checks while blocking insert, update, remove, and dropCollection actions.
Why does an indexing pipeline need the readWrite role?
Indexing pipelines write documents and build search indexes in your database. The readWrite role grants insert, update, createCollection, and createIndex actions needed for those tasks.
Do MongoDB Atlas and self-hosted setups use the same roles?
MongoDB Atlas database users have different built-in roles than self-hosted database users. Still, both platforms build their roles from the same underlying privilege actions.
Related guides
In this post