Registry / database / mongodb-build-info

mongodb-build-info

JSON →
library1.9.11jsnpmunverified

Extracts metadata from MongoDB's buildInfo command to determine deployment type: Atlas, Atlas Data Lake, Enterprise, DocumentDB, or CosmosDB. Also identifies localhost, DigitalOcean, and parse command-line options. Version 1.9.11 is stable and ships TypeScript definitions. Key differentiator: utility library for compass-tools, focused on genuine MongoDB detection and environment identification. Released under Apache-2.0 license. Maintained as part of the mongodb-js/devtools-shared monorepo.

npm install mongodb-build-info
INSTALL
IMPORT
SIG · MONGODB-BUILD-INFO
M
mongodb-build-info
databasejavascriptv1.9.11
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.

getDataLake
import { getDataLake } from 'mongodb-build-info'
const getDataLake = require('mongodb-build-info').getDataLake
Both ESM and CJS are supported; prefer named import for tree-shaking.
isAtlas
import { isAtlas } from 'mongodb-build-info'
No common mistake for this import.
isLocalAtlas
import { isLocalAtlas } from 'mongodb-build-info'
Requires a count function argument; not a direct boolean check.
default import
import * as mongodbBuildInfo from 'mongodb-build-info'
const mongodbBuildInfo = require('mongodb-build-info')
Default import is not a function; you must access named exports.

Connects to MongoDB, retrieves buildInfo and cmdLineOpts, then uses mongodb-build-info to detect DataLake, Enterprise, and genuine MongoDB status.

import { MongoClient } from 'mongodb'; import { getDataLake, isEnterprise, getGenuineMongoDB } from 'mongodb-build-info'; async function main() { const client = new MongoClient('mongodb://localhost:27017'); await client.connect(); const admin = client.db().admin(); const buildInfo = await admin.command({ buildInfo: 1 }); const cmdLineOpts = await admin.command({ getCmdLineOpts: 1 }); const { isDataLake, dlVersion } = getDataLake(buildInfo); console.log('DataLake:', isDataLake, 'version:', dlVersion); const enterprise = isEnterprise(buildInfo); console.log('Enterprise:', enterprise); const { isGenuine, serverName } = getGenuineMongoDB(buildInfo, cmdLineOpts); console.log('Genuine MongoDB:', isGenuine, 'server:', serverName); await client.close(); } main().catch(console.error);
Debug
Known issues
gotchaFunctions like isAtlas, isLocalhost, isDigitalOcean only check the URI string, not actual server metadata. They do not query the server.
fix
Use getGenuineMongoDB with actual server responses for accurate server identity.
affects: >=1.0
breakinggetGenuineMongoDB expects two arguments: buildInfo and cmdLineOpts. Omitting cmdLineOpts returns incorrect isGenuine detection.
fix
Always call getCmdLineOpts command and pass the result as second argument.
affects: >=1.0.0
deprecatedThe default export is not a function. Previous versions allowed require('mongodb-build-info')() - that no longer works.
fix
Use named imports like import { getDataLake } from 'mongodb-build-info'.
affects: >=1.6.0
gotchaisLocalAtlas requires a count function that matches the signature (db, coll, query) => Promise<number>. Supplying wrong signature causes runtime errors.
fix
Ensure count function returns a promise resolving to a number.
affects: >=1.0
Errors
Common errors & fixes
TypeError: getDataLake is not a function
Using default import from CommonJS or destructuring incorrectly.
fix
Use named import: import { getDataLake } from 'mongodb-build-info'
getGenuineMongoDB is not a function
Trying to import as default or using require incorrectly.
fix
Use: const { getGenuineMongoDB } = require('mongodb-build-info');
Must pass cmdLineOpts as second argument
getGenuineMongoDB called with only buildInfo argument.
fix
Call admin.command({ getCmdLineOpts: 1 }) and pass the result as second argument.
Upgrade
Version history
1.9.11latest on npm
Audit
Dependencies
mongodboptionalRequired for running MongoDB commands like buildInfo and getCmdLineOpts to pass results to this library's functions.
Agent activity
6 hits · last 30 days
node
6
Resources
mongodb-build-info — npm install mongodb-build-info · libregistry