mongodb-memory-server-setup

Testing guidelines for MongoDB Memory Server, a tool that runs a temporary MongoDB database on a developer's or CI machine.

In plain words
What is it for?
Use it when adding this database tool to a package or writing tests that start it, including shared version and Vitest timeout settings.
Why use it?
It reduces test failures caused by downloading, unpacking, and caching the MongoDB program taking longer than normal test timeouts.

Cursor rule for Codex

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add rules/prisma/orm/mongodb-memory-server-setup
Clone the repo
git clone --depth 1 https://github.com/prisma/orm

Made for: Codex.

Per session 28 Only the description is in the session, so the agent can decide to use it. The body loads when it is invoked.
When invoked 542 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00028 $0.00542
Opus 5 $0.00014 $0.00271
Sonnet 5 $0.00006 $0.00108
Haiku 4.5 $0.00003 $0.00054

Measured 2d ago against content hash 8b24e48e26d7, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

mongodb-memory-server-setup scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 2d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

Origin

Copies of this mod

1 near-identical copy found in the catalogue:

.agents/rules/mongodb-memory-server-setup.mdc · 54 lines

How it starts

The opening of the file, as written. The whole thing — 54 lines — stays where its author put it; the contents beside it link to each section on GitHub.

mongodb-memory-server setup

When adding mongodb-memory-server (MMS) to a package or writing tests that use it, follow these rules to prevent CI failures.

Version: use the pnpm catalog

MMS is pinned to an exact version in pnpm-workspace.yaml's catalog: section. All consumers must reference it via "mongodb-memory-server": "catalog:" in package.json.

Never use a ^ range or inline version — version drift between packages can cause one package's download to corrupt the shared binary cache used by another.

Vitest config: mandatory timeouts

Every package that depends on MMS must configure its vitest.config.ts with:

import { timeouts } from '@repo/test-utils';
import { defineConfig } from 'vitest/config';

export default defineConfig({
  test: {
    testTimeout: timeouts.spinUpMongoMemoryServer,
    hookTimeout: timeouts.spinUpMongoMemoryServer,
    fileParallelism: false,
  },
});

Why this matters

MMS downloads, extracts, and caches the mongod binary on first use. On CI this happens in the beforeAll hook. If the hook times out mid-download/extraction:

  1. The partially-written binary is left in the shared MMS cache (~/.cache/mongodb-binaries/).
  2. Every subsequent test package that starts MMS executes the corrupted binary.
  3. The corrupted binary crashes with SIGSEGV, causing cascading failures across the entire CI run.

The spinUpMongoMemoryServer timeout (60s × TEST_TIMEOUT_MULTIPLIER) is sized to survive a cold-cache download on CI. The default vitest timeout (10s) is not.

fileParallelism: false

MMS instances within the same package must not start concurrently — parallel replica set startups compete for resources and can cause flaky timeouts.

Checklist for adding MMS to a new package

  1. Add "mongodb-memory-server": "catalog:" to devDependencies
  2. Add "@repo/test-utils": "workspace:*" to devDependencies
  3. Configure vitest.config.ts as shown above
  4. Use timeouts.spinUpMongoMemoryServer for any describe() / beforeAll() / afterAll() timeout overrides in test files
  5. Run pnpm install to update the lockfile

Read the full file on GitHub · 54 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 2d ago First seen · 54 lines · 28 tokens per session scan A 8b24e48e26d7

Subscribe to this mod's changes

mongodb-memory-server-setup is a cursor rule published in the GitHub repository prisma/orm (47,579 stars, last pushed yesterday), licensed Apache-2.0. It adds 28 tokens to every session and 542 once invoked, about $0.0001 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.