Registry / database / mongodb-shell

mongodb-shell

JSON →
library1.0.1jsnpmunverified

A Node.js utility for connecting to and sending commands to a MongoDB shell. Version 1.0.1 is the latest stable release. It provides a simple wrapper around the MongoDB shell process, allowing programmatic command execution and result parsing. Differentiators include lightweight design, Promise-based API, and TypeScript support. Active development with sporadic releases.

npm install mongodb-shell
INSTALL
IMPORT
SIG · MONGODB-SHELL
M
mongodb-shell
databasejavascriptv1.0.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.

MongoShell
import { MongoShell } from 'mongodb-shell'
import MongoShell from 'mongodb-shell'
Named export only; default import not available.
MongoShell
const { MongoShell } = require('mongodb-shell')
const MongoShell = require('mongodb-shell')
CJS usage requires destructuring for named export.

Create a MongoShell instance, execute a command, and clean up resources.

import { MongoShell } from 'mongodb-shell'; async function main() { const mongoShell = new MongoShell('localhost:27017'); try { const result = await mongoShell.sendCommand({ in: 'foo=5' }); console.log(result.out); // '5' } finally { mongoShell.destroy(); } } main().catch(console.error);
Debug
Known issues
gotchaCommand input syntax ('in' field) uses MongoDB shell expression format, not JSON or BSON.
fix
Ensure 'in' contains a valid MongoDB shell command as a string.
affects: >=0.0.0
gotchaThe output ('out') is a string; numeric results are converted to string representation.
fix
Parse or cast the result if expecting non-string types.
affects: >=0.0.0
gotchaRemember to call destroy() to close the shell process; otherwise process may hang.
fix
Always call mongoShell.destroy() after use, ideally in a finally block.
affects: >=0.0.0
Errors
Common errors & fixes
TypeError: Cannot destructure property 'MongoShell' of ... as it is undefined.
Using default import instead of named import.
fix
Use import { MongoShell } from 'mongodb-shell' instead of import MongoShell from 'mongodb-shell'
MongoShell is not a constructor
Using require without destructuring in CommonJS.
fix
Use const { MongoShell } = require('mongodb-shell')
Upgrade
Version history
1.0.1latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
2 hits · last 30 days
node
2
Resources
mongodb-shell — npm install mongodb-shell · libregistry