{"id":13598833,"url":"https://github.com/kpfromer/nestjs-typegoose","last_synced_at":"2025-05-15T01:06:38.529Z","repository":{"id":38434280,"uuid":"129670193","full_name":"kpfromer/nestjs-typegoose","owner":"kpfromer","description":"Typegoose with NestJS","archived":false,"fork":false,"pushed_at":"2025-05-08T08:12:14.000Z","size":5720,"stargazers_count":287,"open_issues_count":115,"forks_count":73,"subscribers_count":7,"default_branch":"master","last_synced_at":"2025-05-12T23:12:13.952Z","etag":null,"topics":["mongoose","nest","nestjs","nestjs-typegoose","typegoose","typescript"],"latest_commit_sha":null,"homepage":"https://kpfromer.github.io/nestjs-typegoose/","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/kpfromer.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","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":"2018-04-16T01:55:53.000Z","updated_at":"2025-04-09T00:59:49.000Z","dependencies_parsed_at":"2023-12-22T02:58:27.684Z","dependency_job_id":"0c00db17-9781-464e-bffe-c4374cb7e770","html_url":"https://github.com/kpfromer/nestjs-typegoose","commit_stats":{"total_commits":471,"total_committers":18,"mean_commits":"26.166666666666668","dds":0.4543524416135881,"last_synced_commit":"de3b8690778967152155503baa5f226808d84cb5"},"previous_names":[],"tags_count":39,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kpfromer%2Fnestjs-typegoose","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kpfromer%2Fnestjs-typegoose/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kpfromer%2Fnestjs-typegoose/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kpfromer%2Fnestjs-typegoose/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kpfromer","download_url":"https://codeload.github.com/kpfromer/nestjs-typegoose/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253838717,"owners_count":21972203,"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":["mongoose","nest","nestjs","nestjs-typegoose","typegoose","typescript"],"created_at":"2024-08-01T17:00:57.268Z","updated_at":"2025-05-15T01:06:38.454Z","avatar_url":"https://github.com/kpfromer.png","language":"TypeScript","funding_links":[],"categories":["Integrations","TypeScript","资源"],"sub_categories":["集成"],"readme":"# nestjs-typegoose\n\n[![NPM](https://nodei.co/npm/nestjs-typegoose.png)](https://nodei.co/npm/nestjs-typegoose/)\n\n[![npm version](https://badge.fury.io/js/nestjs-typegoose.svg)](https://badge.fury.io/js/nestjs-typegoose)\n[![Build Status](https://travis-ci.org/kpfromer/nestjs-typegoose.svg?branch=master)](https://travis-ci.org/kpfromer/nestjs-typegoose)\n[![Coverage Status](https://coveralls.io/repos/github/kpfromer/nestjs-typegoose/badge.svg?branch=master)](https://coveralls.io/github/kpfromer/nestjs-typegoose?branch=master)\n![npm](https://img.shields.io/npm/dm/nestjs-typegoose)\n![npm bundle size](https://img.shields.io/bundlephobia/min/nestjs-typegoose)\n![David](https://img.shields.io/david/peer/kpfromer/nestjs-typegoose)\n\n## Description\n\nInjects [typegoose](https://github.com/szokodiakos/typegoose) models for [nest](https://github.com/nestjs/nest) components and controllers. Typegoose equivalant for [@nestjs/mongoose.](https://docs.nestjs.com/techniques/mongodb)\n\nUsing Typegoose removes the need for having a Model interface.\n\n## Installation\n\n```bash\nnpm install --save nestjs-typegoose\n```\n\nor\n\n```\nyarn add nestjs-typegoose\n```\n\n## Documentation\n\n[Here is the full documentation describing all basic and advanced features.](https://kpfromer.github.io/nestjs-typegoose/)\n\n## Basic usage\n\nYou can checkout the `example` project for more details.\n\n**app.module.ts**\n\n```typescript\nimport { Module } from \"@nestjs/common\";\nimport { TypegooseModule } from \"nestjs-typegoose\";\nimport { CatsModule } from \"./cat.module.ts\";\n\n@Module({\n  imports: [\n    TypegooseModule.forRoot(\"mongodb://localhost:27017/nest\", {\n      useNewUrlParser: true,\n    }),\n    CatsModule,\n  ],\n})\nexport class ApplicationModule {}\n```\n\nCreate class that describes your schema\n\n**cat.model.ts**\n\n```typescript\nimport { prop } from \"@typegoose/typegoose\";\nimport { IsString } from \"class-validator\";\n\nexport class Cat {\n  @IsString()\n  @prop({ required: true })\n  name: string;\n}\n```\n\nInject Cat for `CatsModule`\n\n**cat.module.ts**\n\n```typescript\nimport { Module } from \"@nestjs/common\";\nimport { TypegooseModule } from \"nestjs-typegoose\";\nimport { Cat } from \"./cat.model\";\nimport { CatsController } from \"./cats.controller\";\nimport { CatsService } from \"./cats.service\";\n\n@Module({\n  imports: [TypegooseModule.forFeature([Cat])],\n  controllers: [CatsController],\n  providers: [CatsService],\n})\nexport class CatsModule {}\n```\n\nGet the cat model in a service\n\n**cats.service.ts**\n\n```typescript\nimport { Injectable } from \"@nestjs/common\";\nimport { InjectModel } from \"nestjs-typegoose\";\nimport { Cat } from \"./cat.model\";\nimport { ReturnModelType } from \"@typegoose/typegoose\";\n\n@Injectable()\nexport class CatsService {\n  constructor(\n    @InjectModel(Cat) private readonly catModel: ReturnModelType\u003ctypeof Cat\u003e\n  ) {}\n\n  async create(createCatDto: { name: string }): Promise\u003cCat\u003e {\n    const createdCat = new this.catModel(createCatDto);\n    return await createdCat.save();\n  }\n\n  async findAll(): Promise\u003cCat[] | null\u003e {\n    return await this.catModel.find().exec();\n  }\n}\n```\n\nFinally, use the service in a controller!\n\n**cats.controller.ts**\n\n```typescript\nimport { Controller, Get, Post, Body } from \"@nestjs/common\";\nimport { CatsService } from \"./cats.service\";\nimport { Cat } from \"./cats.model.ts\";\n\n@Controller(\"cats\")\nexport class CatsController {\n  constructor(private readonly catsService: CatsService) {}\n\n  @Get()\n  async getCats(): Promise\u003cCat[] | null\u003e {\n    return await this.catsService.findAll();\n  }\n\n  @Post()\n  async create(@Body() cat: Cat): Promise\u003cCat\u003e {\n    return await this.catsService.create(cat);\n  }\n}\n```\n\n## Requirements\n\n1.  @typegoose/typegoose +6.1.5\n2.  @nestjs/common +6.10.1\n3.  @nestjs/core +6.10.1\n4.  mongoose (with typings `@types/mongoose`) +5.7.12\n\n## License\n\nnestjs-typegoose is [MIT licensed](LICENSE).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkpfromer%2Fnestjs-typegoose","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkpfromer%2Fnestjs-typegoose","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkpfromer%2Fnestjs-typegoose/lists"}