Registry / database / portable-mongodb

portable-mongodb

JSON →
library2.1.14jsnpmunverified

Portable Mongodb is a Node.js package that embeds a fully functional MongoDB server binary within your application, eliminating the need for a separate MongoDB installation. Version 2.1.14 supports only Windows environments. It bundles MongoDB binaries (~4–7 min install) and provides a simple API to start and connect to an embedded database. Unlike mongodb-memory-server, which focuses on temporary in-memory instances, portable-mongodb offers data persistence across sessions. However, it is not maintained as actively and has limited platform support.

npm install portable-mongodb
INSTALL
IMPORT
SIG · PORTABLE-MONGODB
P
portable-mongodb
databasejavascriptv2.1.14
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.

portableMongo
const portableMongo = require('portable-mongodb');
import portableMongo from 'portable-mongodb';
This package is CJS-only and does not provide ESM exports. Use require().
connectToDatabase
await portableMongo.connectToDatabase('dbname');
portableMongo.connectToDatabase({dbName: 'dbname'});
connectToDatabase expects a string (database name), not an options object. Version 2.1.x.
default export
const portableMongo = require('portable-mongodb');
const { connectToDatabase } = require('portable-mongodb');
The package exports a single object with methods; destructuring connectToDatabase directly works but may miss other utilities (none documented).

Starts embedded MongoDB server, connects using Mongoose, inserts a document, and retrieves it.

const portableMongo = require('portable-mongodb'); const mongoose = require('mongoose'); async function main() { await portableMongo.connectToDatabase('my-database'); console.log('Connected to portable MongoDB.'); const schema = new mongoose.Schema({ message: String }); const Model = mongoose.model('Test', schema); await Model.create({ message: 'Hello' }); const docs = await Model.find(); console.log('Documents:', docs); await mongoose.disconnect(); // Note: The embedded server shuts down automatically on process exit. } main().catch(console.error);
Debug
Known issues
breakingThis package only supports Windows. It will fail silently or with obscure errors on macOS/Linux.
fix
Use mongodb-memory-server for cross-platform support, or run on Windows.
affects: >=0.0.0
gotchaInstallation may take 4-7 minutes due to downloading MongoDB binaries (hundreds of MB).
fix
Ensure a stable internet connection and consider using a caching proxy or CI cache.
affects: >=2.0.0
gotchaMongoose is a peer dependency but not declared in package.json. Your project must install it separately.
fix
Run `npm install mongoose` alongside `portable-mongodb`.
affects: >=2.0.0
deprecatedThe package lacks TypeScript definitions. There is no @types/portable-mongodb available.
fix
Use `mongodb-memory-server` which has built-in TS support.
affects: >=2.0.0
gotchaconnectToDatabase requires a string (database name). Passing an object will throw a cryptic error.
fix
Call `connectToDatabase('your-db-name')` instead of an options object.
affects: >=2.0.0
Errors
Common errors & fixes
Error: Cannot find module 'portable-mongodb'
Package not installed or missing from node_modules.
fix
Run `npm install portable-mongodb` and wait for the binary download to complete.
MongooseError: The `uri` parameter to `openUri()` must be a string, got "undefined". Make sure the first parameter to `mongoose.connect()` or `mongoose.createConnection()` is a string.
portableMongo.connectToDatabase() was called incorrectly or failed silently; mongoose.connect() used an undefined URI.
fix
Ensure connectToDatabase is awaited with a valid database name string, and that it resolves successfully before using Mongoose.
UnhandledPromiseRejectionWarning: Error: spawn C:\Users\...\portable-mongodb\bin\ mongod.exe ENOENT
The mongod binary is missing or the path is incorrect. Often happens on non-Windows OS or if the installation was interrupted.
fix
Run on Windows only. If on Windows, reinstall the package with `npm install portable-mongodb`.
TypeError: portableMongo.connect is not a function
Using an older version where the method name was different or incorrect import pattern (e.g., destructuring).
fix
Use `portableMongo.connectToDatabase('dbname')` (the correct method name).
Upgrade
Version history
2.1.14latest on npm
Audit
Dependencies
mongooseoptionalRequired for interacting with the MongoDB instance (schema, models, queries). The package does not ship its own driver.
Agent activity
6 hits · last 30 days
node
6
Resources
portable-mongodb — npm install portable-mongodb · libregistry