Registry /
database / mongodb-memory-server-global-4.4
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-global-4.4';
✗ import MongoMemoryServer from 'mongodb-memory-server-global-4.4';
MongoMemoryServer is a named export, not a default export. This package re-exports the main class pre-configured for MongoDB 4.4.
MongoMemoryServer
✓ const { MongoMemoryServer } = require('mongodb-memory-server-global-4.4');
✗ import { MongoMemoryServer } from 'mongodb-memory-server-global-4.4'; // in CommonJS
While CommonJS `require` is supported, ESM `import` syntax is recommended for newer Node.js versions (>=20.19.0) and TypeScript projects.
MongoMemoryServer.create()
✓ const mongo = await MongoMemoryServer.create();
✗ const mongo = new MongoMemoryServer();
await mongo.start();
The static `create()` method is the recommended asynchronous factory for initializing and starting the server, handling binary download and setup internally.
Demonstrates how to start an in-memory MongoDB 4.4 server, connect a native MongoDB client, perform a basic database operation, and then properly shut down both the client and the server.
import { MongoMemoryServer } from 'mongodb-memory-server-global-4.4';
import { MongoClient } from 'mongodb';
async function runTestDatabase() {
let mongoServer: MongoMemoryServer | null = null;
let client: MongoClient | null = null;
try {
// Start a new in-memory MongoDB server configured for 4.4
mongoServer = await MongoMemoryServer.create();
const mongoUri = mongoServer.getUri();
console.log(`MongoDB Memory Server started at: ${mongoUri}`);
// Connect a MongoDB client to the in-memory server
client = new MongoClient(mongoUri);
await client.connect();
console.log('MongoDB client connected successfully.');
// Perform some database operations
const db = client.db('testdb');
const collection = db.collection('documents');
await collection.insertOne({ name: 'Test Document', value: 1 });
const docs = await collection.find({}).toArray();
console.log('Inserted and found documents:', docs);
} catch (error) {
console.error('Error during test database operations:', error);
} finally {
// Ensure the client and server are always stopped
if (client) {
await client.close();
console.log('MongoDB client closed.');
}
if (mongoServer) {
await mongoServer.stop();
console.log('MongoDB Memory Server stopped.');
}
}
}
runTestDatabase();
Debug
Known issues
breakingmongodb-memory-server-global-4.4 version 11.0.0 and above requires Node.js version 20.19.0 or higher. Older Node.js environments are no longer supported.fixUpgrade your Node.js runtime to version 20.19.0 or newer. Check your `package.json` engines field and CI/CD environments.
affects: >=11.0.0
breakingWhen compiling TypeScript, `mongodb-memory-server-global-4.4` version 11.0.0 upgrades its internal `tsconfig` target to `es2023`. This might cause compilation issues if your project's `tsconfig.json` targets an older ES version or has incompatible settings.fixEnsure your project's `tsconfig.json` is compatible with `es2023` or newer. You might need to update your TypeScript compiler version or adjust your project's `target` setting.
affects: >=11.0.0
gotchaWhile this specific package (`-global-4.4`) is designed for MongoDB 4.4, the underlying `mongodb-memory-server` library (from which this package re-exports) dropped support for MongoDB versions below 4.2.0 in v11.0.0. Attempting to manually configure this package to an unsupported older MongoDB version will fail.fixIf you need an older MongoDB version for testing, you must use an older version of `mongodb-memory-server` or one of its global packages that supports it. For version 4.4, this package is suitable, but do not try to configure it to <4.2.
affects: >=11.0.0
deprecatedThe separate package `mongodb-memory-server-global-4.0` was removed in the v11.0.0 release of the `mongodb-memory-server` ecosystem, as it is no longer supported by the latest MongoDB drivers. Users of that package should upgrade.fixMigrate your tests to use `mongodb-memory-server-global-4.4` or a newer `mongodb-memory-server-global-` package to maintain compatibility with modern MongoDB drivers and Node.js versions.
affects: >=11.0.0 (for users of global-4.0)
Errors
Common errors & fixes
Error: MongoDB binary for version X.Y.Z is not supported on this platform.
The specific MongoDB binary version you are trying to use (or the default set by a package) is not compatible with your operating system or CPU architecture, or it's a version that has been explicitly deprecated by `mongodb-memory-server`.
fixEnsure your system is running a supported architecture (e.g., not an unsupported older macOS/ARM combination for very old MongoDB versions). If you are overriding the version, specify a supported version (e.g., `await MongoMemoryServer.create({ version: '4.4.0' })`). For this package, the version is fixed at 4.4. Error: MongoNetworkError: connect ECONNREFUSED 127.0.0.1:xxxxx
The MongoDB Memory Server instance failed to start correctly, crashed, or was stopped before the client attempted to connect. This can be due to port conflicts, insufficient permissions, or issues with the downloaded binary.
fixVerify that no other process is using the allocated port (the server tries to find a free port automatically, but conflicts can occur). Check the console output for any error messages during `MongoMemoryServer.create()`. Ensure you are awaiting `create()` before attempting to connect a client. Consider adding `await mongoServer.stop()` in a `finally` block or `afterAll` hook to prevent resource leaks.
TypeError: Cannot read properties of undefined (reading 'connect')
This typically occurs when trying to use a MongoDB client (like `MongoClient` or `mongoose`) before the `mongoUri` is properly obtained from a *successfully started* `MongoMemoryServer` instance.
fixEnsure that `MongoMemoryServer.create()` successfully resolves and that `mongoServer.getUri()` is called *after* the server is confirmed to be running. Always handle potential errors from `create()` and subsequent operations.
Audit
Dependencies
No dependency data recorded yet.