Registry / testing / mongodb-memory-server-global-4.2

mongodb-memory-server-global-4.2

JSON →
library11.2.0jsnpmunverified

A sub-package of mongodb-memory-server that automatically downloads a MongoDB 4.2 binary for testing purposes. Version 11.2.0 is current; releases follow mongodb-memory-server core with weekly or monthly cadence. It eliminates the need to manually manage mongod binaries for CI/CD and local test environments. Unlike mongodb-memory-server-core, this package includes the binary download as a postinstall step, making setup effortless. Supports TypeScript with bundled type declarations. Requires Node >=20.19.0 and is ESM-only since v9+. Key differentiator: pre-pinned version (4.2) avoiding version drift in tests.

npm install mongodb-memory-server-global-4.2
INSTALL
IMPORT
SIG · MONGODB-MEMORY-SER
M
mongodb-memory-server-global-4.2
testingjavascriptv11.2.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

MongoMemoryServer
✓ import { MongoMemoryServer } from 'mongodb-memory-server-core'
✗ const { MongoMemoryServer } = require('mongodb-memory-server-core')
ESM-only since v9; CommonJS require will fail. Use default import if you must use require.
MongoMemoryServer (default)
✓ import MongoMemoryServer from 'mongodb-memory-server-core'
✗ const MongoMemoryServer = require('mongodb-memory-server-core')
Default import is deprecated since v8; use named import instead.
MongoMemoryReplSet
✓ import { MongoMemoryReplSet } from 'mongodb-memory-server-core'
Also ESM-only. Ensure tsconfig has 'moduleResolution': 'node16' or 'bundler'.

Creates an in-memory MongoDB 4.2 instance, outputs connection URI, and stops it.

import { MongoMemoryServer } from 'mongodb-memory-server-core'; const mongod = await MongoMemoryServer.create(); const uri = mongod.getUri(); console.log('MongoDB URI:', uri); const db = await mongod.getDbName(); console.log('DB name:', db); // Use uri to connect with mongoose or mongodb driver await mongod.stop();
Debug
Known issues
breakingDefault import of MongoMemoryServer was removed in v9.
fix
Use named import: import { MongoMemoryServer } from 'mongodb-memory-server-core'
affects: >=9.0.0
breakingasync create() no longer accepts instance options; use create(options) instead.
fix
Pass options as argument: await MongoMemoryServer.create({ instance: { port: 27017 } })
affects: >=9.0.0
deprecatedgetUri() and getDbName() are deprecated; use uri and dbName properties after instance creation.
fix
Access mongod.uri instead of mongod.getUri() and mongod.dbName instead of mongod.getDbName()
affects: >=10.0.0
breakingMongoMemoryServer no longer accepts new keyword; use create() static method.
fix
Use await MongoMemoryServer.create() instead of new MongoMemoryServer()
affects: >=9.0.0
gotchaBinary download may fail behind corporate proxies or in restrictive CI environments.
fix
Set HTTP_PROXY/HTTPS_PROXY environment variables or pre-download binary and set MONGOMS_SYSTEM_BINARY.
affects: >=0
breakingNode.js >=20.19.0 required; older versions will not work.
fix
Upgrade Node.js to version 20.19.0 or later.
affects: >=11.0.0
deprecatedallowUseCmd and useCmd options are deprecated.
fix
Remove these options; they are no longer needed.
affects: >=10.0.0
Errors
Common errors & fixes
Error: Cannot find module 'mongodb-memory-server-core'
Missing peer dependency mongodb-memory-server-core or incorrect import from subpackage.
fix
Install mongodb-memory-server-core: npm install mongodb-memory-server-core
TypeError: mongod.getUri is not a function
Using deprecated getUri() in version 10+ where it was removed.
fix
Use mongod.uri property instead.
Error: This module is ESM-only. To use it, you must use ESM imports or dynamic imports.
Using CommonJS require() with version 9+.
fix
Switch to ESM import (import { MongoMemoryServer } from 'mongodb-memory-server-core') or set type: module in package.json.
Error: Failed to download mongod binary version 4.2.0
Network issue or missing system dependencies (like libcurl).
fix
Check internet connection, set proxy variables, or use MONGOMS_SYSTEM_BINARY to point to a pre-installed binary.
TypeError: (intermediate value).create is not a constructor
Using default import instead of named import in v9+.
fix
Use import { MongoMemoryServer } from 'mongodb-memory-server-core'
Upgrade
Version history
11.2.0latest on npm
Audit
Dependencies
mongodb-memory-server-corerequiredProvides the core logic for starting/stopping in-memory MongoDB instances.
mongodb-memory-server-corerequiredThe actual mongod binary is downloaded during core's postinstall step.
Agent activity
15 hits · last 30 days
node
14
Resources
mongodb-memory-server-global-4.2 — npm install mongodb-memory-server-global-4.2 · libregistry