{"id":43762,"library":"resolve-mongodb-srv","title":"resolve-mongodb-srv","description":"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.","status":"active","version":"1.1.7","language":"javascript","source_language":"en","source_url":"https://github.com/mongodb-js/resolve-mongodb-srv","tags":["javascript","mongodb","srv","url","typescript"],"install":[{"cmd":"npm install resolve-mongodb-srv","lang":"bash","label":"npm"},{"cmd":"yarn add resolve-mongodb-srv","lang":"bash","label":"yarn"},{"cmd":"pnpm add resolve-mongodb-srv","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"Package is ESM-only; default export, not named. Use `import` in Node >= 14.","wrong":"const { resolveMongodbSrv } = require('resolve-mongodb-srv')","symbol":"resolveMongodbSrv","correct":"import resolveMongodbSrv from 'resolve-mongodb-srv'"},{"note":"Second argument is an options object; can pass custom dns module.","wrong":"","symbol":"resolveMongodbSrv (with options)","correct":"import resolveMongodbSrv from 'resolve-mongodb-srv'; resolveMongodbSrv('uri', { dns })"},{"note":"Types are included; use `import type` for type-only imports.","wrong":"","symbol":"TypeScript types","correct":"import type ResolveOptions from 'resolve-mongodb-srv'"}],"quickstart":{"code":"import resolveMongodbSrv from 'resolve-mongodb-srv';\n\nasync function main() {\n  try {\n    const resolvedUri = await resolveMongodbSrv(\n      'mongodb+srv://user:password@cluster0.mongodb.net/mydb?retryWrites=true&w=majority'\n    );\n    console.log('Resolved URI:', resolvedUri);\n  } catch (err) {\n    console.error('Resolution failed:', err);\n  }\n}\nmain();","lang":"typescript","description":"Demonstrates resolving a mongodb+srv:// URI to mongodb:// using the default DNS resolver."},"warnings":[{"fix":"Use await or .then() when calling resolveMongodbSrv.","message":"Function is asynchronous and returns a Promise; must be awaited.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Ensure URI follows mongodb+srv:// format. Validate before calling if needed.","message":"Package does not validate MongoDB URI format beyond SRV resolution; invalid URIs may cause errors.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Wrap in try-catch to handle DNS errors like ENOTFOUND.","message":"DNS resolution may fail if network is unavailable or SRV record does not exist; error handling required.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Use the MongoDB driver (mongodb) which handles SRV resolution automatically via connection string.","message":"This package is part of MongoDB Node.js driver internals; direct use is not recommended for typical applications.","severity":"deprecated","affected_versions":">=1.0.0"}],"env_vars":null,"search_vec":"'1.1.7':31 'accord':11 'act':20 'asid':48 'client':65 'connect':7 'depend':47 'discoveri':18 'dns':16,24,51 'driver':29 'esm':38 'includ':40 'initi':15 'javascript':66 'lightweight':43 'mongodb':3,6,14,28,64,67 'need':55 'node.js':50 'npm':36 'pass':61 'pure':23 'record':59 'releas':34 'resolv':2,5,25,57 'resolve-mongodb-srv':1 'runtim':46 'seedlist':17 'specif':19 'srv':4,58,68 'stabl':33 'string':8 'support':37 'type':42 'typescript':41,70 'url':10,69 'use':52 'version':30","created_at":"2026-06-05T17:01:21.820616+00:00","updated_at":"2026-06-05T17:01:21.820616+00:00","problems":[{"fix":"Use import resolveMongodbSrv from 'resolve-mongodb-srv' or enable ESM in your project.","cause":"Using require() instead of import; package is ESM-only.","error":"Error [ERR_REQUIRE_ESM]: require() of ES Module not supported"},{"fix":"Use import resolveMongodbSrv from 'resolve-mongodb-srv' (no curly braces).","cause":"Attempting to call resolveMongodbSrv as a named import ({ resolveMongodbSrv }) when it is a default export.","error":"TypeError: resolveMongodbSrv is not a function"},{"fix":"Check the hostname, network connectivity, and that the SRV record is properly configured.","cause":"DNS lookup failed because the SRV record does not exist or network is down.","error":"Error: querySrv ENOTFOUND _mongodb._tcp.somecluster.mongodb.net"}],"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/mongodb-js/resolve-mongodb-srv","github":"https://github.com/mongodb-js/resolve-mongodb-srv","docs":null,"changelog":null,"pypi":null,"npm":"resolve-mongodb-srv","openapi_spec":null,"status_page":null,"smithery":null,"categories":["database"],"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}}