{"id":13523726,"url":"https://github.com/node-casbin/mongoose-adapter","last_synced_at":"2025-05-07T10:36:18.050Z","repository":{"id":35504049,"uuid":"218026317","full_name":"node-casbin/mongoose-adapter","owner":"node-casbin","description":"Mongoose adapter for Casbin","archived":false,"fork":false,"pushed_at":"2024-01-25T10:46:31.000Z","size":507,"stargazers_count":33,"open_issues_count":3,"forks_count":32,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-10-30T04:28:07.382Z","etag":null,"topics":["access-control","adapter","authorization","casbin","mongodb","mongoose","node-casbin","storage-driver"],"latest_commit_sha":null,"homepage":"https://github.com/casbin/node-casbin","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":"elasticio/casbin-mongoose-adapter","license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/node-casbin.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-10-28T10:58:19.000Z","updated_at":"2024-08-29T08:55:48.000Z","dependencies_parsed_at":"2024-06-18T17:12:19.424Z","dependency_job_id":null,"html_url":"https://github.com/node-casbin/mongoose-adapter","commit_stats":{"total_commits":104,"total_committers":19,"mean_commits":5.473684210526316,"dds":0.7692307692307692,"last_synced_commit":"4b1c1b1ef6542e72edc317e4b8a831f09dcf5706"},"previous_names":[],"tags_count":18,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/node-casbin%2Fmongoose-adapter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/node-casbin%2Fmongoose-adapter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/node-casbin%2Fmongoose-adapter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/node-casbin%2Fmongoose-adapter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/node-casbin","download_url":"https://codeload.github.com/node-casbin/mongoose-adapter/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240766621,"owners_count":19854119,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["access-control","adapter","authorization","casbin","mongodb","mongoose","node-casbin","storage-driver"],"created_at":"2024-08-01T06:01:03.169Z","updated_at":"2025-02-26T00:09:17.202Z","avatar_url":"https://github.com/node-casbin.png","language":"JavaScript","readme":"Mongoose Adapter\n====\n[![NPM version][npm-image]][npm-url]\n[![NPM download][download-image]][download-url]\n[![codebeat badge](https://codebeat.co/badges/c17c9ee1-da42-4db3-8047-9574ad2b23b1)](https://codebeat.co/projects/github-com-node-casbin-mongoose-adapter-master)\n[![Coverage Status](https://coveralls.io/repos/github/node-casbin/mongoose-adapter/badge.svg?branch=master)](https://coveralls.io/github/node-casbin/mongoose-adapter?branch=master)\n[![Discord](https://img.shields.io/discord/1022748306096537660?logo=discord\u0026label=discord\u0026color=5865F2)](https://discord.gg/S5UjpzGZjN)\n[![tests](https://github.com/node-casbin/mongoose-adapter/actions/workflows/main.yml/badge.svg)](https://github.com/node-casbin/mongoose-adapter/actions/workflows/main.yml)\n\n[npm-image]: https://img.shields.io/npm/v/casbin-mongoose-adapter.svg?style=flat-square\n[npm-url]: https://npmjs.org/package/casbin-mongoose-adapter\n[download-image]: https://img.shields.io/npm/dm/casbin-mongoose-adapter.svg?style=flat-square\n[download-url]: https://npmjs.org/package/casbin-mongoose-adapter\n\nMongoose Adapter is the [Mongoose](https://github.com/Automattic/mongoose/) adapter for [Node-Casbin](https://github.com/casbin/node-casbin). With this library, Node-Casbin can load policy from Mongoose supported database or save policy to it. It is originally developed by @ghaiklor from @elasticio.\n\nBased on [Officially Supported Databases](https://mongoosejs.com/docs/), The current supported database is MongoDB.\n\nMongoose Adapter has been rewritten to TypeScript since v3.x.\n\n## Getting Started\n\nInstall the package as dependency in your project:\n\n```bash\nnpm install --save casbin-mongoose-adapter casbin\n```\n**Note**: `casbin` as peerDependencies!\n\nRequire it in a place, where you are instantiating an enforcer ([read more about enforcer here](https://github.com/casbin/node-casbin#get-started)):\n\n```javascript\nconst path = require('path');\nconst { newEnforcer } = require('casbin');\nconst { MongooseAdapter } = require('casbin-mongoose-adapter');\n\n// const MongooseAdapter = require('casbin-mongoose-adapter');\n// You should use this in v2.x\n\nconst model = path.resolve(__dirname, './your_model.conf');\nconst adapter = await MongooseAdapter.newAdapter('mongodb://your_mongodb_uri:27017');\nconst enforcer = await newEnforcer(model, adapter);\n```\n\nThat is all what required for integrating the adapter into casbin.\nCasbin itself calls adapter methods to persist updates you made through it.\n\n## Configuration\n\nYou can pass mongooose-specific options when instantiating the adapter:\n\n```javascript\nconst { MongooseAdapter } = require('casbin-mongoose-adapter');\nconst adapter = await MongooseAdapter.newAdapter('mongodb://your_mongodb_uri:27017', { mongoose_options: 'here' });\n```\n\nAdditional information regard to options you can pass in you can find in [mongoose documentation](https://mongoosejs.com/docs/connections.html#options)\n\n## Filtered Adapter\n\nYou can create an adapter instance that will load only those rules you need to.\n\nA simple case for it is when you have separate policy rules for separate domains (tenants).\nYou do not need to load all the rules for all domains to make an authorization in specific domain.\n\nFor such cases, filtered adapter exists in casbin.\n\n```javascript\nconst { MongooseAdapter } = require('casbin-mongoose-adapter');\nconst adapter = await MongooseAdapter.newFilteredAdapter('mongodb://your_mongodb_uri:27017');\n```\n\n## License\n\n[Apache-2.0](./LICENSE)\n","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnode-casbin%2Fmongoose-adapter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnode-casbin%2Fmongoose-adapter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnode-casbin%2Fmongoose-adapter/lists"}