{"id":16465766,"url":"https://github.com/tony133/nestjs-mongodb-driver","last_synced_at":"2025-07-07T05:04:21.050Z","repository":{"id":37049413,"uuid":"492771979","full_name":"Tony133/nestjs-mongodb-driver","owner":"Tony133","description":"MongoDB Node Driver module for Nest framework (node.js) 😻","archived":false,"fork":false,"pushed_at":"2025-07-01T02:48:10.000Z","size":3447,"stargazers_count":13,"open_issues_count":1,"forks_count":2,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-07-01T03:38:58.309Z","etag":null,"topics":["javascript","mongodb-driver","mongodb-native","mongodb-native-driver","nest","nestjs","nestjs-mongodb-native-driver","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/Tony133.png","metadata":{"files":{"readme":"README.md","changelog":null,"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,"zenodo":null}},"created_at":"2022-05-16T09:42:02.000Z","updated_at":"2025-07-01T02:48:13.000Z","dependencies_parsed_at":"2023-09-26T01:50:07.394Z","dependency_job_id":"5d5859cd-5fed-4542-ab3e-a43637956a1e","html_url":"https://github.com/Tony133/nestjs-mongodb-driver","commit_stats":{"total_commits":872,"total_committers":5,"mean_commits":174.4,"dds":0.1009174311926605,"last_synced_commit":"9bd9dddb3987c1f1ef2b7f8af79037196ec4ce20"},"previous_names":[],"tags_count":21,"template":false,"template_full_name":null,"purl":"pkg:github/Tony133/nestjs-mongodb-driver","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Tony133%2Fnestjs-mongodb-driver","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Tony133%2Fnestjs-mongodb-driver/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Tony133%2Fnestjs-mongodb-driver/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Tony133%2Fnestjs-mongodb-driver/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Tony133","download_url":"https://codeload.github.com/Tony133/nestjs-mongodb-driver/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Tony133%2Fnestjs-mongodb-driver/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":264016716,"owners_count":23544625,"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":["javascript","mongodb-driver","mongodb-native","mongodb-native-driver","nest","nestjs","nestjs-mongodb-native-driver","typescript"],"created_at":"2024-10-11T11:35:09.896Z","updated_at":"2025-07-07T05:04:21.028Z","avatar_url":"https://github.com/Tony133.png","language":"TypeScript","funding_links":["https://opencollective.com/nest","https://paypal.me/kamilmysliwiec"],"categories":[],"sub_categories":[],"readme":"\u003cp align=\"center\"\u003e\n  \u003ca href=\"http://nestjs.com/\" target=\"blank\"\u003e\u003cimg src=\"https://nestjs.com/img/logo-small.svg\" width=\"200\" alt=\"Nest Logo\" /\u003e\u003c/a\u003e\n\u003c/p\u003e\n\n[circleci-image]: https://img.shields.io/circleci/build/github/nestjs/nest/master?token=abc123def456\n[circleci-url]: https://circleci.com/gh/nestjs/nest\n\n  \u003cp align=\"center\"\u003eA progressive \u003ca href=\"http://nodejs.org\" target=\"_blank\"\u003eNode.js\u003c/a\u003e framework for building efficient and scalable server-side applications.\u003c/p\u003e\n    \u003cp align=\"center\"\u003e\n\u003ca href=\"https://www.npmjs.com/~nestjscore\" target=\"_blank\"\u003e\u003cimg src=\"https://img.shields.io/npm/v/@nestjs/core.svg\" alt=\"NPM Version\" /\u003e\u003c/a\u003e\n\u003ca href=\"https://www.npmjs.com/~nestjscore\" target=\"_blank\"\u003e\u003cimg src=\"https://img.shields.io/npm/l/@nestjs/core.svg\" alt=\"Package License\" /\u003e\u003c/a\u003e\n\u003ca href=\"https://www.npmjs.com/~nestjscore\" target=\"_blank\"\u003e\u003cimg src=\"https://img.shields.io/npm/dm/@nestjs/common.svg\" alt=\"NPM Downloads\" /\u003e\u003c/a\u003e\n\u003ca href=\"https://circleci.com/gh/nestjs/nest\" target=\"_blank\"\u003e\u003cimg src=\"https://img.shields.io/circleci/build/github/nestjs/nest/master\" alt=\"CircleCI\" /\u003e\u003c/a\u003e\n\u003ca href=\"https://coveralls.io/github/nestjs/nest?branch=master\" target=\"_blank\"\u003e\u003cimg src=\"https://coveralls.io/repos/github/nestjs/nest/badge.svg?branch=master#9\" alt=\"Coverage\" /\u003e\u003c/a\u003e\n\u003ca href=\"https://discord.gg/G7Qnnhy\" target=\"_blank\"\u003e\u003cimg src=\"https://img.shields.io/badge/discord-online-brightgreen.svg\" alt=\"Discord\"/\u003e\u003c/a\u003e\n\u003ca href=\"https://opencollective.com/nest#backer\" target=\"_blank\"\u003e\u003cimg src=\"https://opencollective.com/nest/backers/badge.svg\" alt=\"Backers on Open Collective\" /\u003e\u003c/a\u003e\n\u003ca href=\"https://opencollective.com/nest#sponsor\" target=\"_blank\"\u003e\u003cimg src=\"https://opencollective.com/nest/sponsors/badge.svg\" alt=\"Sponsors on Open Collective\" /\u003e\u003c/a\u003e\n  \u003ca href=\"https://paypal.me/kamilmysliwiec\" target=\"_blank\"\u003e\u003cimg src=\"https://img.shields.io/badge/Donate-PayPal-ff3f59.svg\"/\u003e\u003c/a\u003e\n    \u003ca href=\"https://opencollective.com/nest#sponsor\"  target=\"_blank\"\u003e\u003cimg src=\"https://img.shields.io/badge/Support%20us-Open%20Collective-41B883.svg\" alt=\"Support us\"\u003e\u003c/a\u003e\n  \u003ca href=\"https://twitter.com/nestframework\" target=\"_blank\"\u003e\u003cimg src=\"https://img.shields.io/twitter/follow/nestframework.svg?style=social\u0026label=Follow\"\u003e\u003c/a\u003e\n\u003c/p\u003e\n  \u003c!--[![Backers on Open Collective](https://opencollective.com/nest/backers/badge.svg)](https://opencollective.com/nest#backer)\n  [![Sponsors on Open Collective](https://opencollective.com/nest/sponsors/badge.svg)](https://opencollective.com/nest#sponsor)--\u003e\n\n## Description\n\nMongoDB Native Driver module for Nest framework (node.js) 😻\n\n## Installation\n\nFirst install the module via `yarn` or `npm` or `pnpm` and do not forget to install the driver package as well:\n\n\n```bash\n    $ npm i --save nest-mongodb-driver mongodb\n```\nor\n\n```bash\n    $ yarn add nest-mongodb-driver mongodb\n```\nor\n\n```bash\n    $ pnpm add nest-mongodb-driver mongodb\n```\n\n## Table of Contents\n\n- [Description](#description)\n- [Table of Contents](#table-of-contents)\n- [Usage](#usage)\n  - [MongoDbDriverModule](#mongodbdrivermodule)\n  - [MultiConnectionsDatabase](#multi-connections-database)\n  - [ExampleOfUse](#example-of-use)\n\n## Usage\n\n### MongoDbDriverModule\n\nMongoDbDriverModule is the primary entry point for this package and can be used synchronously\n\n```typescript\n@Module({\n  imports: [\n    MongoDbDriverModule.forRoot({\n        url: 'mongodb://localhost:27017/[:nameDb]',\n    }),\n  ],\n})\n```\n\nor asynchronously\n\n```typescript\n@Module({\n  imports: [\n    MongoDbDriverModule.forRootAsync({\n      useFactory: () =\u003e ({\n        url: 'mongodb://localhost:27017/[:nameDb]',\n      }),\n    }),\n  ],\n})\n```\n\n## Example of use\n\nUsersService:\n\n```typescript\nimport { Injectable } from '@nestjs/common';\nimport { Db, ObjectId } from 'mongodb';\nimport { InjectClient } from 'nest-mongodb-driver';\nimport type {\n  Document,\n} from 'mongodb';\n\n@Injectable()\nexport class UsersService {\n  constructor(@InjectClient() private readonly db: Db) {}\n\n  async findAll(): Promise\u003cDocument[]\u003e {\n    return await this.db.collection('users').find().toArray();\n  }\n}\n```\n\nUsersController:\n\n```typescript\nimport { Controller, Get } from '@nestjs/common';\nimport { UsersService } from './users.service';\nimport type {\n  Document,\n} from 'mongodb';\n\n@Controller()\nexport class UsersController {\n  constructor(private readonly usersService: UsersService) {}\n\n  @Get()\n  async getAllUsers(): Promise\u003cDocument[]\u003e {\n    return await this.usersService.findAll();\n  }\n}\n```\n\n## Multi Connections Database\n\n```typescript\n@Module({\n  imports: [\n    MongoDbDriverModule.forRootAsync(\n      {\n        useFactory: () =\u003e ({\n          url: 'mongodb://localhost:27017/test1',\n        }),\n      },\n      'db1Connection',\n    ),\n    MongoDbDriverModule.forRootAsync(\n      {\n        useFactory: () =\u003e ({\n          url: 'mongodb://localhost:27018/test2',\n        }),\n      },\n      'db2Connection',\n    ),\n  ],\n  controllers: [],\n  providers: [],\n})\nexport class AppModule {}\n```\n\nUsage example with Multi Connection\n\nPostService:\n\n```typescript\n@Injectable()\nexport class PostService {\n  constructor(\n    @InjectConnection('db2Connection')\n    private dbConnection: Db,\n  ) {}\n\n  public async findAll(): Promise\u003cDocument[]\u003e {\n    return await this.dbConnection.collection('posts').find().toArray();\n  }\n\n  public async create(createPostDto: CreatePostDto): Promise\u003cInsertOneResult\u003cDocument\u003e\u003e {\n    try {\n      return await this.dbConnection\n        .collection('posts')\n        .insertOne(createPostDto);\n    } catch (err) {\n      throw new HttpException(err, HttpStatus.BAD_REQUEST);\n    }\n  }\n```\n\nUsersService:\n\n```typescript\n@Injectable()\nexport class UsersService {\n  constructor(\n    @InjectConnection('db1Connection')\n    private dbConnection: Db,\n  ) {}\n\n  public async findAll(): Promise\u003cDocument[]\u003e {\n    return await this.dbConnection.collection('users').find().toArray();\n  }\n\n  public async create(createUserDto: CreateUserDto): Promise\u003cInsertOneResult\u003cDocument\u003e\u003e {\n    try {\n      return await this.dbConnection\n        .collection('users')\n        .insertOne(createUserDto);\n    } catch (err) {\n      throw new HttpException(err, HttpStatus.BAD_REQUEST);\n    }\n  }\n}\n```\n\nFor more information on `MongoDB NodeJS Driver` see [here](https://www.mongodb.com/docs/drivers/node/current/)\n\n## Contribute\nFeel free to help this library, I'm quite busy with also another Nestjs packages, but the community will appreciate the effort of improving this library. Make sure you follow the guidelines\n\n## Stay in touch\n\n- Author - [Tony133](https://github.com/Tony133)\n- Framework - [https://nestjs.com](https://nestjs.com/)\n\n## License\n\n [MIT licensed](LICENSE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftony133%2Fnestjs-mongodb-driver","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftony133%2Fnestjs-mongodb-driver","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftony133%2Fnestjs-mongodb-driver/lists"}