mongodb-memory-server-setup

A testing rule for using mongodb-memory-server, a tool that runs a temporary MongoDB database for tests.

In plain words
What is it for?
Use it when adding mongodb-memory-server to a package or writing Vitest tests that start an in-memory MongoDB instance.
Why use it?
It helps prevent continuous-integration test failures caused by mismatched versions, slow database startup, or interrupted binary downloads.

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/prisma-next/mongodb-memory-server-setup
Clone the repo
git clone --depth 1 https://github.com/prisma/prisma-next

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 546 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
Origin 94% copy Near-identical to another mod 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.00546
Opus 5 $0.00014 $0.00273
Sonnet 5 $0.00006 $0.00109
Haiku 4.5 $0.00003 $0.00055

Measured 2d ago against content hash 4bd8f3beb63a, 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

This is a copy

94% identical to mongodb-memory-server-setup — 4 lines differ, which has more behind it and is treated as the original. This page carries a canonical link to it rather than competing with it.

.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 '@prisma-next/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 "@prisma-next/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 4bd8f3beb63a

Subscribe to this mod's changes

mongodb-memory-server-setup is a cursor rule published in the GitHub repository prisma/prisma-next (421 stars, last pushed 7d ago), licensed Apache-2.0. It adds 28 tokens to every session and 546 once invoked, about $0.0001 per session on Opus 5. A static security scan graded it A with 0 findings. It is 94% identical to mongodb-memory-server-setup, differing in 4 lines, and is treated as a copy.