Registry / security / mongodb-security

mongodb-security

JSON →
library1.6.0jsnpmunverified

Portable business logic for the MongoDB security model, providing utilities to humanize MongoDB privilege resources and check user privileges against actions. Version 1.6.0 is the current stable release; the package is part of the MongoDB Compass ecosystem but has not seen updates since 2016. It offers functions like humanize() to convert resource objects to literate strings and getResourcesWithActions() to filter resources by allowed actions, simplifying MongoDB authorization checks.

npm install mongodb-security
INSTALL
IMPORT
SIG · MONGODB-SECURITY
M
mongodb-security
securityjavascriptv1.6.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.

humanize
const { humanize } = require('mongodb-security');
var security = require('mongodb-security'); var humanize = security.humanize;
Package uses CommonJS; destructure from require for clarity.
getResourcesWithActions
const { getResourcesWithActions } = require('mongodb-security');
const getResourcesWithActions = require('mongodb-security').getResourcesWithActions;
Same as above; destructure for clean imports.
default import
const security = require('mongodb-security');
import security from 'mongodb-security';
This package does not support ES modules; use require().

Shows how to use humanize() to convert MongoDB privilege resources to readable strings, and getResourcesWithActions() to filter resources by allowed actions.

const security = require('mongodb-security'); // Humanize a cluster resource const clusterResource = { cluster: true }; console.log(security.humanize(clusterResource)); // 'For the deployment' // Humanize a collection resource const collResource = { db: 'mydb', collection: 'mycoll' }; console.log(security.humanize(collResource)); // 'On mydb.mycoll' // Check user privileges // Assume user object from db.command({ usersInfo: ..., showPrivileges: true }) const user = { user: 'testUser', db: 'admin', inheritedPrivileges: [ { resource: { db: '', collection: '' }, actions: ['find'] } ] }; const resources = security.getResourcesWithActions(user, ['find'], 'collection'); console.log(resources); // [{ db: '', collection: '' }]
Debug
Known issues
gotchaPackage is not actively maintained; last release in 2016. May not work with modern MongoDB driver versions.
fix
Consider using the MongoDB Node.js driver directly for privilege checks, or fork the package.
affects: >=1.6.0
gotchaThe humanize() function returns strings that are not localized; only English output.
fix
Accept English-only output or implement custom localization.
affects: all
gotchaNo TypeScript type definitions shipped. TypeScript users must create own types or use @types/mongodb-security if available.
fix
Install @types/mongodb-security from DefinitelyTyped or write a declaration file.
affects: all
Errors
Common errors & fixes
Cannot find module 'mongodb-security'
Package not installed or missing from node_modules.
fix
Run npm install mongodb-security
security.humanize is not a function
Incorrect import: using ES import syntax on CJS module.
fix
Use const security = require('mongodb-security'); instead of import.
TypeError: user.inheritedPrivileges is undefined
User object does not have inheritedPrivileges property; getResourcesWithActions expects that property.
fix
Ensure user object is retrieved with showPrivileges: true in the usersInfo command.
Upgrade
Version history
1.6.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
17 hits · last 30 days
node
12
Resources
mongodb-security — npm install mongodb-security · libregistry