{"id":26509619,"url":"https://github.com/haplifeman/mongo-adonis","last_synced_at":"2026-04-20T05:03:43.839Z","repository":{"id":282741300,"uuid":"949497065","full_name":"HapLifeMan/mongo-adonis","owner":"HapLifeMan","description":"mongo-lucid is a MongoDB adapter for AdonisJS 6's Lucid ORM, enabling seamless integration with the latest MongoDB versions.","archived":false,"fork":false,"pushed_at":"2025-03-19T17:15:11.000Z","size":96,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-19T17:15:16.547Z","etag":null,"topics":["adonis","adonis-framework","adonisjs","lucid","mongo","mongodb","nodejs","orm","typescript"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/HapLifeMan.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE.md","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":"2025-03-16T15:41:29.000Z","updated_at":"2025-03-19T17:15:14.000Z","dependencies_parsed_at":"2025-03-19T17:15:20.108Z","dependency_job_id":"b294ffd4-2243-4aaf-b43d-dfe5b62ffb23","html_url":"https://github.com/HapLifeMan/mongo-adonis","commit_stats":null,"previous_names":["haplifeman/lucid-mongodb","haplifeman/mongo-lucid","haplifeman/mongo-adonis"],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HapLifeMan%2Fmongo-adonis","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HapLifeMan%2Fmongo-adonis/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HapLifeMan%2Fmongo-adonis/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HapLifeMan%2Fmongo-adonis/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/HapLifeMan","download_url":"https://codeload.github.com/HapLifeMan/mongo-adonis/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244717437,"owners_count":20498299,"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":["adonis","adonis-framework","adonisjs","lucid","mongo","mongodb","nodejs","orm","typescript"],"created_at":"2025-03-21T01:19:48.370Z","updated_at":"2026-04-20T05:03:43.824Z","avatar_url":"https://github.com/HapLifeMan.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![npm-image]][npm-url] [![license-image]][license-url] [![adonisjs-image]][adonisjs-url] [![mongodb-image]][mongodb-url] [![nodejs-image]][nodejs-url] ![typescript-image]\n\n\n# Adonis x Lucid x Mongo\n\n\u003e [!WARNING]\n\u003e 🚧 This package is in active development and may contain breaking changes. While it contains 100+ tests to ensure reliability, I recommend using it in production with caution. The documentation may not be up-to-date and can have inconsistent information. Thanks for your understanding!\n\n\u003e Leverage the power of objects in Node.js with MongoDB's object-oriented database and AdonisJS 6's Lucid ORM. Built specifically for AdonisJS 6, `mongo-adonis` supports latest MongoDB versions.\n\n## ✨ Features\n\n- 🔌 **Seamless MongoDB Integration**: Use MongoDB with the familiar Lucid ORM API\n- 🎯 **TypeScript First**: Full type safety and autocompletion\n- 🔄 **Active Record Pattern**: Intuitive model-based database operations\n- 🔗 **Rich Relationships**: Support for HasOne, HasMany, BelongsTo relationships\n- 🎨 **Decorator Support**: Clean and declarative model definitions\n- 🔍 **Powerful Query Builder**: Fluent API for complex queries\n- 🧠 **Direct MongoDB Access**: Use MongoDB's native API directly with `db.collection.find({})`\n- 🔐 **Built-in Auth Support**: Works seamlessly with AdonisJS 6 auth\n- 🔄 **Advanced Serialization**: Fine-grained control over JSON representation\n- 📦 **Zero Configuration**: Get started with minimal setup\n\n## 🗺️ Roadmap\n\n- [ ] Create boilerplate\n- [ ] Improve query builder\n- [ ] Many-to-Many relationships\n- [ ] Paginate methods\n- [ ] ? Migrations\n- [ ] ? Factories\n- [ ] ? Seeds\n\n## 🚀 Quick Start\n\n### 1. Install the Package\n\n```bash\nbun install mongo-adonis\n```\n\n### 2. Configure the Provider\n\n```bash\nnode ace configure mongo-adonis\n```\n\n### 3. Fill Environment Variables\n\n```env\nDB_CONNECTION=mongodb\nDB_HOST=127.0.0.1\nDB_PORT=27017\nDB_USER=\nDB_PASSWORD=\nDB_DATABASE=mongo-adonis\nDB_AUTH_SOURCE=admin\n```\n\n## 📝 Usage Examples\n\n### Basic Model Definition\n\n```ts\nimport { MongoModel, column, ObjectId } from 'mongo-adonis'\n\nexport class Post extends MongoModel {\n  @column({ isPrimary: true })\n  declare _id: ObjectId\n\n  @column()\n  declare name: string\n\n  @column()\n  declare description: string\n\n  @column()\n  declare content: string\n}\n```\n\n### CRUD Operations\n\n```ts\n// Create\nconst user = await User.create({\n  name: 'John Doe',\n  email: 'john@example.com',\n  password: 'secret'\n})\n\n// Read\nconst user = await User.find('60a1e2c3d4e5f6a7b8c9d0e1')\nconst users = await User.all()\n\n// Update\nuser.name = 'Jane Doe'\nawait user.save()\n\n// Delete\nawait user.delete()\n```\n\n### Advanced Queries\n\n```ts\n// Complex queries with the fluent API\nconst activeUsers = await User.query()\n  .where('status', 'active')\n  .where('age', '\u003e=', 18)\n  .orderBy('name', 'asc')\n  .limit(10)\n  .offset(0)\n  .all()\n```\n\n### Relationships\n\n```ts\nimport { column, hasMany, belongsTo, ObjectId, MongoModel } from 'mongo-adonis'\n\nexport class User extends MongoModel {\n  @column({ isPrimary: true })\n  declare _id: ObjectId\n\n  @column()\n  declare name: string\n\n  @hasMany(() =\u003e Post)\n  declare posts: HasMany\u003ctypeof Post\u003e\n}\n\nexport class Post extends MongoModel {\n  @column({ isPrimary: true })\n  declare _id: ObjectId\n\n  @column()\n  declare title: string\n\n  @belongsTo(() =\u003e User)\n  declare user: BelongsTo\u003ctypeof User\u003e\n}\n```\n\n### Working with Relationships\n\n```ts\n// Create a user with posts\nconst user = await User.create({\n  name: 'John Doe',\n  email: 'john@example.com'\n})\n\n// Create posts for the user\nawait user.posts.create({\n  title: 'First Post',\n  content: 'Hello World!'\n})\n\nawait user.posts.createMany([\n  {\n    title: 'Second Post',\n    content: 'Another post',\n  },\n  {\n    title: 'Third Post',\n    content: 'Another one',\n  }\n])\n\n// Load user with their posts\nconst userWithPosts = await User.query().where('_id', user._id).first()\n\n// Get all posts for a user\nconst userPosts = await user.posts.all()\n\n// Find a post and load its user\nconst post = await Post.query().where('_id', postId).first()\n\n// Get the user of a post\nconst postUser = await post.user.exec()\n\n// Update a post's user\nconst newUser = await User.find(newUserId)\nawait post.user.associate(newUser)\n\n// Remove a post from a user\nawait post.user.dissociate()\n```\n\n## 🔐 Authentication\n\nWorks seamlessly with AdonisJS 6 auth, update the `app/models/user.ts` file:\n\n```ts\nimport { DateTime } from 'luxon'\nimport hash from '@adonisjs/core/services/hash'\nimport { compose } from '@adonisjs/core/helpers'\nimport { MongoModel, column, withAuthFinder, ObjectId } from 'mongo-adonis'\n\nconst AuthFinder = withAuthFinder(() =\u003e hash.use('scrypt'), {\n  uids: ['email'],\n  passwordColumnName: 'password',\n})\n\nexport default class User extends compose(MongoModel, AuthFinder) {\n  @column({ isPrimary: true })\n  declare _id: ObjectId\n\n  @column()\n  declare email: string\n\n  @column({ serialize: false })\n  declare password: string\n\n  @column.dateTime({ autoCreate: true })\n  declare createdAt: DateTime\n\n  @column.dateTime({ autoCreate: true, autoUpdate: true })\n  declare updatedAt: DateTime\n}\n```\n\n## 🤝 Contributing\n\nPlease see our [Contributing Guide](CONTRIBUTING.md) for details.\n\n## 📄 License\n\nMIT License - see the [LICENSE.md](LICENSE.md) file for details.\n\n---\n\n[npm-image]: https://img.shields.io/npm/v/mongo-adonis.svg\n[npm-url]: https://npmjs.org/package/mongo-adonis\n[license-image]: https://img.shields.io/npm/l/mongo-adonis\n[license-url]: LICENSE.md\n[adonisjs-image]: https://img.shields.io/badge/AdonisJS-6-5A45FF\n[adonisjs-url]: https://adonisjs.com\n[mongodb-image]: https://img.shields.io/badge/MongoDB-4.0--8.0-47A248\n[mongodb-url]: https://www.mongodb.com/docs/drivers/node/current/compatibility/\n[nodejs-image]: https://img.shields.io/badge/Node.js-16--22-339933\n[nodejs-url]: https://www.mongodb.com/docs/drivers/node/current/compatibility/\n[typescript-image]: https://img.shields.io/badge/TypeScript-3178C6","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhaplifeman%2Fmongo-adonis","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhaplifeman%2Fmongo-adonis","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhaplifeman%2Fmongo-adonis/lists"}