Registry / devops / get-mongodb-version

get-mongodb-version

JSON →
library2.0.1jsnpmunverified

CLI and API to retrieve the MongoDB version from a local mongod binary path, a running MongoDB URI, or a Db instance. v2.0.1 is stable but low activity; maintained as part of MongoDB-js ecosystem. Differentiates from manual parsing by abstracting `--version` execution and server connection/serverInfo queries into a single function call.

npm install get-mongodb-version
INSTALL
IMPORT
SIG · GET-MONGODB-VERSIO
G
get-mongodb-version
devopsjavascriptv2.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.

default
import getMongodbVersion from 'get-mongodb-version'
const getMongodbVersion = require('get-mongodb-version')
ESM-only since v2. CommonJS require will not work without bundler.
getMongodbVersion (CJS compat)
const getMongodbVersion = require('get-mongodb-version')
const { getMongodbVersion } = require('get-mongodb-version')
Default export is a function; named destructure fails.
getMongodbVersion (with Db instance)
getMongodbVersion(db, callback)
getMongodbVersion({ db: db }, callback)
Pass the Db instance directly, not wrapped in an object.

Demonstrates retrieving MongoDB version from a binary path and from a URI using the library.

import getMongodbVersion from 'get-mongodb-version'; // Get version from a local mongod path const path = '/usr/local/bin/mongod'; getMongodbVersion(path, (err, version) => { if (err) return console.error(err); console.log('Version:', version); }); // Or from a URI (requires mongodb driver) const uri = 'mongodb://localhost:27017'; getMongodbVersion(uri, (err, version) => { if (err) return console.error(err); console.log('Version:', version); });
Debug
Known issues
breakingv2.0.0 dropped support for Node < 10 and switched to ES module.
fix
Update to Node >=10 and use import/ESM syntax.
affects: <2.0.0
deprecatedPassing an options object with 'db' property is no longer supported; pass Db instance directly.
fix
Call getMongodbVersion(db, callback) instead of getMongodbVersion({ db: db }, callback).
affects: >=2.0.0
gotchaWhen using a URI, the 'mongodb' driver must be installed separately as a peer dependency.
fix
Run npm install mongodb in your project.
affects: >=2.0.0
gotchaThe CLI command is 'get-mongodb-version' and may conflict if global install is not used.
fix
Ensure the package is installed globally or use npx.
affects: all
Errors
Common errors & fixes
Error: Cannot find module 'get-mongodb-version'
Package not installed or wrong import style.
fix
npm install get-mongodb-version
TypeError: getMongodbVersion is not a function
Using named import instead of default import.
fix
Use import getMongodbVersion from 'get-mongodb-version' or const getMongodbVersion = require('get-mongodb-version')
Error: connect ECONNREFUSED 127.0.0.1:27017
MongoDB not running on the provided URI.
fix
Start mongod or check the URI.
TypeError: db.admin is not a function
Passed a Db instance wrapped in an object.
fix
Pass the Db instance directly: getMongodbVersion(db, callback)
Upgrade
Version history
2.0.1latest on npm
Audit
Dependencies
mongodboptionalNeeded when connecting to a URI to query serverInfo().version
debugoptionalUsed for debug logging
Agent activity
6 hits · last 30 days
node
6
Resources
get-mongodb-version — npm install get-mongodb-version · libregistry