https://github.com/zakodium/adonis-mongodb
MongoDB provider for AdonisJS 5
https://github.com/zakodium/adonis-mongodb
adonisjs mongodb provider
Last synced: 5 months ago
JSON representation
MongoDB provider for AdonisJS 5
- Host: GitHub
- URL: https://github.com/zakodium/adonis-mongodb
- Owner: zakodium
- License: other
- Created: 2019-12-03T14:30:03.000Z (over 6 years ago)
- Default Branch: main
- Last Pushed: 2025-01-15T14:16:59.000Z (over 1 year ago)
- Last Synced: 2025-10-20T10:41:48.762Z (8 months ago)
- Topics: adonisjs, mongodb, provider
- Language: TypeScript
- Homepage: https://zakodium.github.io/adonis-mongodb/
- Size: 863 KB
- Stars: 65
- Watchers: 3
- Forks: 11
- Open Issues: 28
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# Adonis MongoDB
MongoDB provider for AdonisJS 5.
Maintained by Zakodium
[![NPM version][npm-image]][npm-url]
[![build status][ci-image]][ci-url]
[![Test coverage][codecov-image]][codecov-url]
[![npm download][download-image]][download-url]
| :warning: This module is unstable and in active development. Use at your own risk. |
| ---------------------------------------------------------------------------------- |
## Prerequisites
This provider requires AdonisJS v5 and won't work with AdonisJS v4.
We recommend using MongoDB >=5.0. Earlier versions are not tested.
## Installation
```console
npm i @zakodium/adonis-mongodb
node ace configure @zakodium/adonis-mongodb
```
## Documentation
### Using with the authentication provider
Adonis MongoDB can be used to authenticate users with the `@adonisjs/auth` addon.
To enable it, edit the following files:
#### `contracts/auth.ts`
Example of a configuration with the session guard:
```ts
import {
MongodbModelAuthProviderContract,
MongodbModelAuthProviderConfig,
} from '@ioc:Zakodium/Mongodb/Odm';
import User from 'App/Models/User';
declare module '@ioc:Adonis/Addons/Auth' {
interface ProvidersList {
user: {
implementation: MongodbModelAuthProviderContract;
config: MongodbModelAuthProviderConfig;
};
}
interface GuardsList {
web: {
implementation: SessionGuardContract<'user', 'web'>;
config: SessionGuardConfig<'user'>;
};
}
}
```
#### `config/auth.ts`
```ts
import { AuthConfig } from '@ioc:Adonis/Addons/Auth';
const authConfig: AuthConfig = {
guard: 'web',
guards: {
web: {
driver: 'session',
provider: {
driver: 'mongodb-model',
},
},
},
};
export default authConfig;
```
## Development
To run tests locally:
```bash
docker compose up -d
node reset-dev.mjs
npm test
docker compose down
```
## License
[MIT](./LICENSE)
[npm-image]: https://img.shields.io/npm/v/@zakodium/adonis-mongodb.svg
[npm-url]: https://www.npmjs.com/package/@zakodium/adonis-mongodb
[ci-image]: https://github.com/zakodium/adonis-mongodb/workflows/Node.js%20CI/badge.svg?branch=main
[ci-url]: https://github.com/zakodium/adonis-mongodb/actions?query=workflow%3A%22Node.js+CI%22
[codecov-image]: https://img.shields.io/codecov/c/github/zakodium/adonis-mongodb.svg
[codecov-url]: https://codecov.io/gh/zakodium/adonis-mongodb
[download-image]: https://img.shields.io/npm/dm/@zakodium/adonis-mongodb.svg
[download-url]: https://www.npmjs.com/package/@zakodium/adonis-mongodb