npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@crashlab/mongo

v0.1.14

Published

High-fidelity MongoDB proxy for deterministic simulation testing.

Downloads

745

Readme

@crashlab/mongo

High-fidelity MongoDB proxy for deterministic simulation testing.

Instead of a partial JS-only mock, this package uses a TCP Proxy model to route traffic from your application to a real MongoDB binary (mongodb-memory-server). This ensures 100% protocol fidelity — including complex aggregation pipelines, transactions, and change streams — while still allowing CrashLab to inject deterministic virtual latency.

Features

  • 100% Fidelity: Since it proxies to a real mongod process, every MongoDB feature works exactly as it does in production.
  • Per-Seed Isolation: Each simulation seed automatically uses a unique database name (sim_db_<seed>) which is dropped after the run.
  • Virtual Latency: Integrated with @crashlab/tcp and @crashlab/clock to hold response bytes until the virtual clock advances.
  • Assertion API: Direct access to the database via env.mongo.find() for easy test assertions without needing a separate driver setup in your scenario.

Installation

npm install --save-dev @crashlab/mongo

Note: This package is included by default in the main crashlab package.

Usage (Internal CrashLab API)

In a CrashLab scenario, @crashlab/mongo is available on the env object:

export default async function scenario(env) {
  // 1. The environment automatically rewrites MONGODB_URI to point to the proxy
  const client = await MongoClient.connect(process.env.MONGODB_URI);
  const db = client.db();

  // 2. Perform operations (these will be intercepted and proxied)
  await db.collection('users').insertOne({ name: 'Alice' });

  // 3. Advance virtual time (the proxy holds the response until this happens)
  await env.clock.advance(50);

  // 4. Use the assertion API to verify state directly
  const users = await env.mongo.find('users', { name: 'Alice' });
  if (users.length !== 1) throw new Error('User not found');
}

How it Works

  1. Shared Server: The Simulation runner starts one MongoMemoryServer process for the entire test run.
  2. TCP Interception: When your app connects to localhost:27017, @crashlab/tcp intercepts the connection.
  3. Message Framing: MongoMock reassembles raw TCP chunks into valid MongoDB wire-protocol frames (based on the 4-byte length prefix).
  4. Latency Injection: Complete response frames from the real mongod are held by the Scheduler and only released to your app when the virtual clock reaches the scheduled time.
  5. Auto-Cleanup: The mongo.drop() method is called after every seed to ensure the shared process stays clean for the next run.

License

MIT