MongoDB adapter for Node Casbin (v2.0.0, 2024) providing policy storage and retrieval using MongoDB. Implements FilteredAdapter, BatchAdapter, and UpdatableAdapter interfaces, with automatic index creation and timestamp support. Differentiators include support for filtered policies, batch updates, and manual save control. Compatible with casbin v5.x. Active development with Apache 2.0/MIT licensing.
npm install mongodb-casbin-adapterNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Initializes a Casbin enforcer with MongoDB adapter, enforces a simple policy, and closes the adapter.
Update imports to use ES module syntax: import { MongoAdapter } from 'mongodb-casbin-adapter'.Replace new MongoAdapter(...) with await MongoAdapter.newAdapter(...).
Set dropCollectionOnManualSave: false unless you want to purge all policies on save.
Upgrade to v2 and switch to ESM import.
Use { uri, database, collection, options: { ... } } where options contains MongoDB client options.Use await MongoAdapter.newAdapter(config) instead of new MongoAdapter(config).
Install with npm install mongodb-casbin-adapter and use import syntax in an ESM environment.
Call adapter.close() to close the MongoDB connection, not enforcer.close().
Provide a valid collection string: { collection: 'policies' }