Registry / security / nestjs-casbin-mongodb

nestjs-casbin-mongodb

JSON →
library1.2.5jsnpmunverified

A NestJS module integrating Casbin with a MongoDB adapter for policy storage. Current stable version is 1.2.5, with no updates since 2021. It provides a ready-to-use module that configures Casbin with MongoDB as the policy backend, supporting model files and custom collections. Key differentiators include tight integration with NestJS dependency injection and a simple forRoot setup. Compared to alternatives like nestjs-casbin, this package specifically targets MongoDB users and avoids the need to manually configure adapters.

npm install nestjs-casbin-mongodb
INSTALL
IMPORT
SIG · NESTJS-CASBIN-MONG
N
nestjs-casbin-mongodb
securityjavascriptv1.2.5
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.

NestCasbinModule
import { NestCasbinModule } from 'nestjs-casbin-mongodb'
const { NestCasbinModule } = require('nestjs-casbin-mongodb')
Module is ESM-only; named import must be used.

Shows how to set up NestJS Casbin module with MongoDB adapter, including configuration parameters.

import { Module } from '@nestjs/common'; import { NestCasbinModule } from 'nestjs-casbin-mongodb'; import { join } from 'path'; @Module({ imports: [ NestCasbinModule.forRoot({ uri: process.env.MONGO_URI ?? 'mongodb://localhost:27017', casbinModelPath: join(__dirname, './rbac_model.conf'), collectionName: 'casbin_rule', databaseName: 'casbin_db', }), ], }) export class AppModule {}
Debug
Known issues
breakingPackage does not support casbin v5+ due to API changes in the adapter interface.
fix
Use casbin v4.x and mongodb driver v3.x or pin versions in package.json.
affects: >=1.0.0
deprecatedThe package has not been updated since 2021 and may contain unpatched vulnerabilities.
fix
Consider migrating to nestjs-casbin with a separate MongoDB adapter.
affects: >=1.0.0
gotchaIf you omit the 'collectionName' option, it defaults to 'casbin_rule' which may conflict with existing collections.
fix
Always specify a unique 'collectionName' or ensure the default is acceptable.
affects: >=1.0.0
Errors
Common errors & fixes
Cannot find module 'nestjs-casbin-mongodb'
Running npm install without peer dependencies being installed correctly.
fix
Run 'npm install nestjs-casbin-mongodb @nestjs/common casbin mongodb' to include all peer deps.
MongoError: failed to connect to server [localhost:27017]
MongoDB connection URI is misconfigured or MongoDB is not running.
fix
Ensure MongoDB is running and the URI is correct, e.g., 'mongodb://localhost:27017/my-db'.
Upgrade
Version history
1.2.5latest on npm
Audit
Dependencies
@nestjs/commonrequiredPeer dependency required for NestJS decorators and module system
casbinrequiredPeer dependency providing the core Casbin authorization library
mongodbrequiredPeer dependency needed for MongoDB Native Driver to connect and query the database
Agent activity
8 hits · last 30 days
node
8
Resources
nestjs-casbin-mongodb — npm install nestjs-casbin-mongodb · libregistry