{"id":43160,"library":"mongodb-memory-server-global-4.0","title":"MongoDB Memory Server (Global 4.0)","description":"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.","status":"active","version":"10.4.1","language":"javascript","source_language":"en","source_url":"https://github.com/typegoose/mongodb-memory-server","tags":["javascript","mongodb","mongoose","mock","stub","mockgoose","mongodb-prebuilt","mongomem","typescript"],"install":[{"cmd":"npm install mongodb-memory-server-global-4.0","lang":"bash","label":"npm"},{"cmd":"yarn add mongodb-memory-server-global-4.0","lang":"bash","label":"yarn"},{"cmd":"pnpm add mongodb-memory-server-global-4.0","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"peer dependency; provides the core functionality and binary management","package":"mongodb-memory-server-core","optional":false}],"imports":[{"note":"This export is from mongodb-memory-server-core, not the sub-package. The sub-package only configures the binary version.","wrong":"import { MongoMemoryServer } from 'mongodb-memory-server-global-4.0'","symbol":"MongoMemoryServer","correct":"import { MongoMemoryServer } from 'mongodb-memory-server-core'"},{"note":"Same as above: all exports are from core.","wrong":"import { createMongoInstance } from 'mongodb-memory-server-global-4.0'","symbol":"createMongoInstance","correct":"import { createMongoInstance } from 'mongodb-memory-server-core'"},{"note":"CommonJS users must require from mongodb-memory-server-core and access the property.","wrong":"const MongoMemoryServer = require('mongodb-memory-server-global-4.0');","symbol":"default (require)","correct":"const MongoMemoryServer = require('mongodb-memory-server-core').MongoMemoryServer;"}],"quickstart":{"code":"import { MongoMemoryServer } from 'mongodb-memory-server-core';\n\nasync function start() {\n  const mongod = await MongoMemoryServer.create({\n    instance: {\n      dbName: 'test',\n    },\n    binary: {\n      version: process.env.MONGODB_VERSION ?? '4.0.28',\n    },\n  });\n  const uri = mongod.getUri();\n  console.log(`MongoDB URI: ${uri}`);\n  // Use the URI with mongoose or driver\n  await mongod.stop();\n}\n\nstart().catch(console.error);","lang":"typescript","description":"Creates an in-memory MongoDB instance with explicit version 4.0 and logs the connection URI."},"warnings":[{"fix":"Update Node.js to >=16.20.1.","message":"Version 10.0.0 dropped Node.js 12 and 14 support (minimum Node 16.20.1).","severity":"breaking","affected_versions":">=10.0.0"},{"fix":"Migrate to mongodb-memory-server-core and specify binary version in options.","message":"As 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.","severity":"deprecated","affected_versions":">=10.0.0"},{"fix":"Always import from 'mongodb-memory-server-core'.","message":"The sub-package does not export any classes; it only auto-configures the binary download path. Using it directly will not provide MongoMemoryServer.","severity":"gotcha","affected_versions":"all"},{"fix":"Set MONGOMS_SYSTEM_BINARY or use mongodb-memory-server-core with 'binary.downloadDir' option.","message":"Binary download happens synchronously on first import, which can block event loop; use environment variables or pre-download in CI.","severity":"gotcha","affected_versions":"all"},{"fix":"Specify version explicitly via options to avoid unexpected changes.","message":"Version 8.0.0 changed default binary version from 'latest' to a fixed version, causing potential version mismatch.","severity":"breaking","affected_versions":">=8.0.0 <9.0.0"}],"env_vars":null,"search_vec":"'/.cache/mongodb-binaries':66 '10.4.1':38 '4.0':5,11,30 'align':43 'also':89 'altern':91 'automat':23 'binari':31,59,92 'cach':63 'core':98 'current':34 'custom':100 'differenti':68 'download':24,57,101 'e.g':93 'first':61 'global':4,10,65 'in-memori':51 'instanc':55 'integr':82 'javascript':102 'key':67 'local':28 'main':46,87 'manag':26 'memori':2,8,20,53,96 'mock':105 'mockgoos':107 'mongodb':1,7,19,29,54,73,95,103,109 'mongodb-memory-serv':18 'mongodb-memory-server-cor':94 'mongodb-memory-server-glob':6 'mongodb-prebuilt':108 'mongomem':111 'mongoos':85,104 'month':40 'multipl':75 'need':70 'offer':90 'packag':16,47,80,88 'prebuilt':110 'provid':49 'releas':39 'run':62 'seamless':83 'server':3,9,21,97 'stabl':35 'stub':106 'sub':15,79 'sub-packag':14,78 'support':74 'system':72 'test':33 'typescript':112 'updat':42 'version':36,76 'via':77","created_at":"2026-06-05T16:58:28.271646+00:00","updated_at":"2026-06-05T16:58:28.271646+00:00","problems":[{"fix":"Change import to 'mongodb-memory-server-core'.","cause":"Importing from the wrong package (mongodb-memory-server-global-4.0) which doesn't export it.","error":"MongoMemoryServer is not a constructor"},{"fix":"Run 'npm install mongodb-memory-server-core'.","cause":"The sub-package only has a peer dependency on core; core may not be installed.","error":"Cannot find module 'mongodb-memory-server-core'"},{"fix":"Upgrade Node.js to v16.20.1 or later.","cause":"The package requires Node >=16.20.1.","error":"Node.js version 12 is unsupported"},{"fix":"Ensure network access for download, or set environment variable MONGOMS_SYSTEM_BINARY to a local binary path.","cause":"Binary download failed or not present.","error":"Error: spawn ./mongod ENOENT"}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":null,"cli_version":null,"type":"library","homepage":"https://github.com/typegoose/mongodb-memory-server","github":"https://github.com/typegoose/mongodb-memory-server","docs":null,"changelog":null,"pypi":null,"npm":"mongodb-memory-server-global-4.0","openapi_spec":null,"status_page":null,"smithery":null,"categories":["testing"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-05","next_check":"2026-09-03","install_tag":null}}