Registry /
database / mongodb-memory-server-global
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
muslnode 18–226 runs
build_error
glibcnode 18–226 runs
build_error
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
MongoMemoryServer
✓ import { MongoMemoryServer } from 'mongodb-memory-server'
✗ import { MongoMemoryServer } from 'mongodb-memory-server-global'
The 'mongodb-memory-server-global' package primarily manages binary downloads. For programmatic control (starting/stopping the server), import `MongoMemoryServer` from the core `mongodb-memory-server` package.
MongoMemoryReplSet
✓ import { MongoMemoryReplSet } from 'mongodb-memory-server'
✗ const { MongoMemoryReplSet } = require('mongodb-memory-server-global')
Similar to `MongoMemoryServer`, replication set functionality is exported by `mongodb-memory-server`. Use named imports for ESM environments, and `require` for CommonJS.
start
✓ import { start } from 'mongodb-memory-server'
✗ import * as MMS from 'mongodb-memory-server'
For a simpler API to just start the server without explicit class instantiation, `start` is available as a named export from `mongodb-memory-server`. Avoid star imports unless necessary for specific legacy patterns.
Demonstrates starting an in-memory MongoDB instance, connecting with Mongoose, performing basic CRUD operations, and then cleaning up the connection and server. This setup implicitly relies on `mongodb-memory-server-global` having pre-downloaded the necessary binaries.
import { MongoMemoryServer } from 'mongodb-memory-server';
import mongoose from 'mongoose';
async function runInMemoryDbTest() {
// mongodb-memory-server-global ensures binaries are available.
// MongoMemoryServer handles the in-memory instance.
const mongod = await MongoMemoryServer.create();
const uri = mongod.getUri();
console.log(`MongoDB Memory Server started at: ${uri}`);
try {
await mongoose.connect(uri);
console.log('Mongoose connected to in-memory MongoDB');
const UserSchema = new mongoose.Schema({ name: String, email: String });
const User = mongoose.model('User', UserSchema);
const newUser = await User.create({ name: 'Test User', email: 'test@example.com' });
console.log('User created:', newUser);
const foundUser = await User.findOne({ name: 'Test User' });
console.log('User found:', foundUser);
} catch (error) {
console.error('Error during test:', error);
} finally {
await mongoose.disconnect();
console.log('Mongoose disconnected.');
await mongod.stop();
console.log('MongoDB Memory Server stopped.');
}
}
runInMemoryDbTest();
Debug
Known issues
breakingThe default MongoDB binary version used by `mongodb-memory-server` has been updated to 8.2.x. This might affect tests expecting older MongoDB behavior or specific features.fixIf specific MongoDB versions are required, set the `mongodb-version` configuration option (e.g., in `package.json` or via environment variables) to pin to an older version, for example `MONGOMS_VERSION=7.0.0`.
affects: >=11.0.0
breakingSupport for MongoDB versions below 4.2.0 has been removed. Trying to specify older versions will result in download or startup failures.fixEnsure your project's MongoDB version requirements are 4.2.0 or higher. Update your `mongodb-version` configuration if you were using an unsupported version.
affects: >=11.0.0
breakingThe minimum supported Node.js version is now 20.19.0. Running on older Node.js environments will lead to errors.fixUpgrade your Node.js environment to version 20.19.0 or higher. Use a Node.js version manager like `nvm` to manage multiple Node.js versions.
affects: >=11.0.0
breakingThe TypeScript target in the project's `tsconfig` has been upgraded to `es2023`. This could potentially cause issues in projects with older TypeScript configurations or environments expecting a different target.fixUpdate your project's `tsconfig.json` to be compatible with `es2023` or ensure your build process correctly transpiles newer ECMAScript features.
affects: >=11.0.0
deprecatedThe specific package `mongodb-memory-server-global-4.0` has been removed as MongoDB 4.0 is no longer supported by the latest MongoDB driver.fixMigrate your tests and applications to use a newer MongoDB version (4.2.0 or higher) and the main `mongodb-memory-server-global` package.
affects: >=11.0.0
gotchaBinary download failures can occur due to network issues or incorrect proxy configurations. Recent versions include fixes for `USE_HTTP` requests.fixEnsure stable internet connectivity. If behind a proxy, configure `HTTP_PROXY` or `HTTPS_PROXY` environment variables. For specific issues, setting `MONGOMS_USE_HTTP=1` might resolve download problems caused by `http` module limitations in some environments.
affects: >=10.4.3, >=11.0.1
Errors
Common errors & fixes
Error: MongoDB binary for version X.Y.Z not found.
The `mongodb-memory-server-global` package failed to download the required MongoDB binary during installation, or the specified version is unsupported/unavailable.
fixCheck your network connection and proxy settings. Ensure the requested MongoDB version is supported by `mongodb-memory-server` (e.g., >=4.2.0 for v11+). Try deleting the `~/.cache/mongodb-binaries` directory and reinstalling, or manually specify a supported version with the `MONGOMS_VERSION` environment variable.
TypeError: MongoMemoryServer.create is not a function
Attempting to use `MongoMemoryServer` directly from `mongodb-memory-server-global` instead of `mongodb-memory-server`.
fixChange your import statement from `import { MongoMemoryServer } from 'mongodb-memory-server-global'` to `import { MongoMemoryServer } from 'mongodb-memory-server'`. Node.js vX.Y.Z is not supported. Please use Node.js >= 20.19.0
Running `mongodb-memory-server` with an unsupported Node.js version.
fixUpgrade your Node.js environment to version 20.19.0 or newer. Consider using a Node Version Manager (NVM) to manage different Node.js versions for various projects.
Audit
Dependencies
mongodb-memory-serverrequiredThis package handles binary downloads; actual programmatic server control is provided by 'mongodb-memory-server'.
mongodboptionalUsed by Mongoose or the MongoDB Node.js driver to connect to the server.
mongooseoptionalA popular ODM that often utilizes mongodb-memory-server for testing.