Registry / database / resolve-mongodb-srv

resolve-mongodb-srv

JSON →
library1.1.7jsnpmunverified

Resolves mongodb+srv:// connection strings to mongodb:// URLs according to the MongoDB Initial DNS Seedlist Discovery specification. Acts as a pure DNS resolver, not a MongoDB driver. Version 1.1.7 is stable, released on npm. Supports ESM and includes TypeScript types. Lightweight with no runtime dependencies aside from Node.js DNS. Use when you need to resolve SRV records before passing to a MongoDB client.

npm install resolve-mongodb-srv
INSTALL
IMPORT
SIG · RESOLVE-MONGODB-SR
R
resolve-mongodb-srv
databasejavascriptv1.1.7
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.

resolveMongodbSrv
✓ import resolveMongodbSrv from 'resolve-mongodb-srv'
✗ const { resolveMongodbSrv } = require('resolve-mongodb-srv')
Package is ESM-only; default export, not named. Use `import` in Node >= 14.
resolveMongodbSrv (with options)
✓ import resolveMongodbSrv from 'resolve-mongodb-srv'; resolveMongodbSrv('uri', { dns })
Second argument is an options object; can pass custom dns module.
TypeScript types
✓ import type ResolveOptions from 'resolve-mongodb-srv'
Types are included; use `import type` for type-only imports.

Demonstrates resolving a mongodb+srv:// URI to mongodb:// using the default DNS resolver.

import resolveMongodbSrv from 'resolve-mongodb-srv'; async function main() { try { const resolvedUri = await resolveMongodbSrv( 'mongodb+srv://user:password@cluster0.mongodb.net/mydb?retryWrites=true&w=majority' ); console.log('Resolved URI:', resolvedUri); } catch (err) { console.error('Resolution failed:', err); } } main();
Debug
Known issues
gotchaFunction is asynchronous and returns a Promise; must be awaited.
fix
Use await or .then() when calling resolveMongodbSrv.
affects: >=1.0.0
gotchaPackage does not validate MongoDB URI format beyond SRV resolution; invalid URIs may cause errors.
fix
Ensure URI follows mongodb+srv:// format. Validate before calling if needed.
affects: >=1.0.0
gotchaDNS resolution may fail if network is unavailable or SRV record does not exist; error handling required.
fix
Wrap in try-catch to handle DNS errors like ENOTFOUND.
affects: >=1.0.0
deprecatedThis package is part of MongoDB Node.js driver internals; direct use is not recommended for typical applications.
fix
Use the MongoDB driver (mongodb) which handles SRV resolution automatically via connection string.
affects: >=1.0.0
Errors
Common errors & fixes
Error [ERR_REQUIRE_ESM]: require() of ES Module not supported
Using require() instead of import; package is ESM-only.
fix
Use import resolveMongodbSrv from 'resolve-mongodb-srv' or enable ESM in your project.
TypeError: resolveMongodbSrv is not a function
Attempting to call resolveMongodbSrv as a named import ({ resolveMongodbSrv }) when it is a default export.
fix
Use import resolveMongodbSrv from 'resolve-mongodb-srv' (no curly braces).
Error: querySrv ENOTFOUND _mongodb._tcp.somecluster.mongodb.net
DNS lookup failed because the SRV record does not exist or network is down.
fix
Check the hostname, network connectivity, and that the SRV record is properly configured.
Upgrade
Version history
1.1.7latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
8 hits · last 30 days
node
8
Resources
resolve-mongodb-srv — npm install resolve-mongodb-srv · libregistry