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

mongodb-memory-server-global-4.0

JSON →
library10.4.1jsnpmunverified

mongodb-memory-server-global-4.0 is a sub-package of mongodb-memory-server that automatically downloads and manages a local MongoDB 4.0 binary for testing. Current stable version is 10.4.1, released monthly with updates aligned with the main package. It provides an in-memory MongoDB instance that downloads the binary on first run, caching it globally (~/.cache/mongodb-binaries). Key differentiators: no need for system MongoDB, supports multiple versions via sub-packages, and integrates seamlessly with Mongoose. The main package also offers alternative binaries (e.g., mongodb-memory-server-core) for custom downloads.

npm install mongodb-memory-server-global-4.0
INSTALL
IMPORT
SIG · MONGODB-MEMORY-SER
M
mongodb-memory-server-global-4.0
testingjavascriptv10.4.1
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'
✗ import { MongoMemoryServer } from 'mongodb-memory-server-global-4.0'
This export is from mongodb-memory-server-core, not the sub-package. The sub-package only configures the binary version.
createMongoInstance
✓ import { createMongoInstance } from 'mongodb-memory-server-core'
✗ import { createMongoInstance } from 'mongodb-memory-server-global-4.0'
Same as above: all exports are from core.
default (require)
✓ const MongoMemoryServer = require('mongodb-memory-server-core').MongoMemoryServer;
✗ const MongoMemoryServer = require('mongodb-memory-server-global-4.0');
CommonJS users must require from mongodb-memory-server-core and access the property.

Creates an in-memory MongoDB instance with explicit version 4.0 and logs the connection URI.

import { MongoMemoryServer } from 'mongodb-memory-server-core'; async function start() { const mongod = await MongoMemoryServer.create({ instance: { dbName: 'test', }, binary: { version: process.env.MONGODB_VERSION ?? '4.0.28', }, }); const uri = mongod.getUri(); console.log(`MongoDB URI: ${uri}`); // Use the URI with mongoose or driver await mongod.stop(); } start().catch(console.error);
Debug
Known issues
breakingVersion 10.0.0 dropped Node.js 12 and 14 support (minimum Node 16.20.1).
fix
Update Node.js to >=16.20.1.
affects: >=10.0.0
deprecatedAs of version 10.0.0, mongodb-memory-server-global-4.0 is deprecated in favor of using mongodb-memory-server-core with explicit binary version.
fix
Migrate to mongodb-memory-server-core and specify binary version in options.
affects: >=10.0.0
gotchaThe sub-package does not export any classes; it only auto-configures the binary download path. Using it directly will not provide MongoMemoryServer.
fix
Always import from 'mongodb-memory-server-core'.
affects: all
gotchaBinary download happens synchronously on first import, which can block event loop; use environment variables or pre-download in CI.
fix
Set MONGOMS_SYSTEM_BINARY or use mongodb-memory-server-core with 'binary.downloadDir' option.
affects: all
breakingVersion 8.0.0 changed default binary version from 'latest' to a fixed version, causing potential version mismatch.
fix
Specify version explicitly via options to avoid unexpected changes.
affects: >=8.0.0 <9.0.0
Errors
Common errors & fixes
MongoMemoryServer is not a constructor
Importing from the wrong package (mongodb-memory-server-global-4.0) which doesn't export it.
fix
Change import to 'mongodb-memory-server-core'.
Cannot find module 'mongodb-memory-server-core'
The sub-package only has a peer dependency on core; core may not be installed.
fix
Run 'npm install mongodb-memory-server-core'.
Node.js version 12 is unsupported
The package requires Node >=16.20.1.
fix
Upgrade Node.js to v16.20.1 or later.
Error: spawn ./mongod ENOENT
Binary download failed or not present.
fix
Ensure network access for download, or set environment variable MONGOMS_SYSTEM_BINARY to a local binary path.
Upgrade
Version history
10.4.1latest on npm
Audit
Dependencies
mongodb-memory-server-corerequiredpeer dependency; provides the core functionality and binary management
Agent activity
13 hits · last 30 days
node
12
Resources
mongodb-memory-server-global-4.0 — npm install mongodb-memory-server-global-4.0 · libregistry