Registry / devops / mongodb-shell-to-url

mongodb-shell-to-url

JSON →
library0.1.0jsnpmunverified

A small utility (v0.1.0, last updated 2016) that converts MongoDB shell connection strings from Atlas into a standard MongoDB URL. Maintained by MongoDB-js, it parses shell commands like `mongo "mongodb://..." --ssl --username user` and outputs a connection URL with parameters. Known limitations: requires double-quoted URI, ignores password (replaces with PASSWORD), does not support --hostname/--port, and only works when the URL contains a query string. Not actively developed; considered stable for its narrow use case.

npm install mongodb-shell-to-url
INSTALL
IMPORT
SIG · MONGODB-SHELL-TO-U
M
mongodb-shell-to-url
devopsjavascriptv0.1.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.

default
import shellToUrl from 'mongodb-shell-to-url';
const { shellToUrl } = require('mongodb-shell-to-url');
Package only exports a single default function. CommonJS require returns the function directly, not an object.
default (CommonJS)
const shellToUrl = require('mongodb-shell-to-url');
CommonJS style is the original API. ESM import works as default import.
default (TypeScript)
import shellToUrl from 'mongodb-shell-to-url';
TypeScript users should use default import. No type definitions provided; use @types/mongodb-shell-to-url if needed.

Parses a MongoDB shell connection string and outputs a connection URL with query parameters.

import shellToUrl from 'mongodb-shell-to-url'; const shellCmd = 'mongo "mongodb://localhost:27017?replicaSet=MyCluster" --ssl --username hans'; const url = shellToUrl(shellCmd); console.log(url); // Output: mongodb://hans:PASSWORD@localhost:27017?ssl=true&replicaSet=MyCluster&authSource=admin
Debug
Known issues
gotchaThe password is hard-coded to 'PASSWORD' in the output; the actual password is not extracted.
fix
Manually replace 'PASSWORD' with the real password in the output string.
affects: >=0.1.0
gotchaThe input MongoDB URI must be in double quotes. Single quotes or no quotes will cause parse failure.
fix
Ensure the shell command uses double quotes around the URI: mongo "mongodb://..."
affects: >=0.1.0
gotchaThe function only works if the MongoDB URI contains a query string (a '?' character). URIs without query parameters will fail.
fix
Add a query string to the URI (e.g., ?ssl=true) even if empty, or manually construct URL.
affects: >=0.1.0
gotchaOptions --hostname and --port are not supported. They are ignored and not reflected in output.
fix
Use the full URI format in the shell command instead of --hostname/--port.
affects: >=0.1.0
Errors
Common errors & fixes
TypeError: shellToUrl is not a function
Using destructured require: const { shellToUrl } = require('mongodb-shell-to-url')
fix
Use default import: const shellToUrl = require('mongodb-shell-to-url') or import shellToUrl from 'mongodb-shell-to-url'
Error: Could not find a question mark in the connection string
Input URI does not contain a '?' (no query string)
fix
Ensure the shell URI includes a query string, e.g., mongodb://localhost:27017?replicaSet=MyCluster
Error: Could not find a URI in double quotes
The MongoDB URI in the shell command is not wrapped in double quotes
fix
Wrap the URI in double quotes: mongo "mongodb://..."
Upgrade
Version history
0.1.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
9 hits · last 30 days
node
8
Resources