{"id":13455750,"url":"https://github.com/typegoose/typegoose","last_synced_at":"2026-02-28T12:47:20.969Z","repository":{"id":37336155,"uuid":"184794628","full_name":"typegoose/typegoose","owner":"typegoose","description":"Typegoose - Define Mongoose models using TypeScript classes.","archived":false,"fork":false,"pushed_at":"2025-05-03T14:53:12.000Z","size":30663,"stargazers_count":2266,"open_issues_count":21,"forks_count":139,"subscribers_count":18,"default_branch":"master","last_synced_at":"2025-05-07T06:43:37.407Z","etag":null,"topics":["db","js","model","models","mongodb","mongoose","nodejs","odm","ts","typescript"],"latest_commit_sha":null,"homepage":"https://typegoose.github.io/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/typegoose.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":".github/CONTRIBUTING.md","funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":".github/SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null},"funding":{"open_collective":"typegoose"}},"created_at":"2019-05-03T17:26:27.000Z","updated_at":"2025-05-06T15:15:14.000Z","dependencies_parsed_at":"2023-07-16T19:14:49.652Z","dependency_job_id":"66198f28-9b78-48df-bb47-3cf5cfc46366","html_url":"https://github.com/typegoose/typegoose","commit_stats":{"total_commits":2486,"total_committers":109,"mean_commits":"22.807339449541285","dds":"0.21842316975060339","last_synced_commit":"3826b049b92a666b0ccb8085d2367ae4f503c8ba"},"previous_names":["hasezoey/typegoose"],"tags_count":257,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/typegoose%2Ftypegoose","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/typegoose%2Ftypegoose/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/typegoose%2Ftypegoose/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/typegoose%2Ftypegoose/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/typegoose","download_url":"https://codeload.github.com/typegoose/typegoose/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252831176,"owners_count":21810779,"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":["db","js","model","models","mongodb","mongoose","nodejs","odm","ts","typescript"],"created_at":"2024-07-31T08:01:10.510Z","updated_at":"2026-02-28T12:47:20.897Z","avatar_url":"https://github.com/typegoose.png","language":"TypeScript","readme":"# Typegoose\n\n\u003csub\u003e(These badges are from typegoose:master)\u003c/sub\u003e  \n[![Node.js Tests](https://github.com/typegoose/typegoose/workflows/Node.js%20Tests/badge.svg?branch=master)](https://github.com/typegoose/typegoose/actions?query=workflow%3A\"Node.js+Tests\")\n[![codecov.io](https://codecov.io/github/typegoose/typegoose/coverage.svg?branch=master)](https://codecov.io/github/typegoose/typegoose?branch=master)\n[![npm](https://img.shields.io/npm/dt/@typegoose/typegoose.svg)](https://www.npmjs.com/package/@typegoose/typegoose)\n\nDefine Mongoose models using TypeScript classes\n\n## Migration\n\nMigration Guides:  \n(Date format: `dd-mm-yyyy`)\n\n- [11 to 12](https://typegoose.github.io/typegoose/versions/beta/docs/guides/migration/migrate-12) (released on `25-11-2023`)\n- [10 to 11](https://typegoose.github.io/typegoose/docs/guides/migration/migrate-11) (released on `27-03-2023`)\n- [9 to 10](https://typegoose.github.io/typegoose/docs/guides/migration/migrate-10) (released on `12-12-2022`)\n- [8 to 9](https://typegoose.github.io/typegoose/docs/guides/migration/migrate-9) (released on `22-09-2021`)\n- [7 to 8](https://typegoose.github.io/typegoose/docs/guides/migration/migrate-8) (released on `28-07-2021`)\n- [6 to 7](https://typegoose.github.io/typegoose/docs/guides/migration/migrate-7) (released on `01-04-2020`)\n- [5 to 6](https://typegoose.github.io/typegoose/docs/guides/migration/migrate-6) (released on `30-09-2019`)\n\n## Basic usage\n\n```ts\nimport { prop, getModelForClass } from '@typegoose/typegoose';\nimport mongoose from 'mongoose';\n\nclass User {\n  @prop()\n  public name?: string;\n\n  @prop({ type: () =\u003e [String] })\n  public jobs?: string[];\n}\n\nconst UserModel = getModelForClass(User); // UserModel is a regular Mongoose Model with correct types\n\n(async () =\u003e {\n  await mongoose.connect('mongodb://localhost:27017/', { dbName: 'test' });\n\n  const { _id: id } = await UserModel.create({ name: 'JohnDoe', jobs: ['Cleaner'] });\n  const user = await UserModel.findById(id).exec();\n\n  console.log(user); // prints { _id: 59218f686409d670a97e53e0, name: 'JohnDoe', __v: 0 }\n})();\n```\n\n## Motivation\n\nA common problem when using Mongoose with TypeScript is that you have to define both the Mongoose model and the TypeScript interface. If the model changes, you also have to keep the TypeScript interface file in sync or the TypeScript interface would not represent the real data structure of the model.\n\nTypegoose aims to solve this problem by defining only a TypeScript interface (class), which needs to be enhanced with special Typegoose decorators (like `@prop`).\n\nUnder the hood it uses the Reflect \u0026 [reflect-metadata](https://github.com/rbuckton/reflect-metadata) API to retrieve the types of the properties, so redundancy can be significantly reduced.\n\nInstead of writing this:\n\n```ts\n// This is a representation of how typegoose's compile output would look like\ninterface Car {\n  model?: string;\n}\n\ninterface Job {\n  title?: string;\n  position?: string;\n}\n\ninterface User {\n  name?: string;\n  age!: number;\n  preferences?: string[];\n  mainJob?: Job;\n  jobs?: Job[];\n  mainCar?: Car | string;\n  cars?: (Car | string)[];\n}\n\nconst JobSchema = new mongoose.Schema({\n  title: String;\n  position: String;\n});\n\nconst CarModel = mongoose.model('Car', {\n  model: string,\n});\n\nconst UserModel = mongoose.model('User', {\n  name: { type: String },\n  age: { type: Number, required: true },\n  preferences: [{ type: String }],\n  mainJob: { type: JobSchema },\n  jobs: [{ type: JobSchema }],\n  mainCar: { type: Schema.Types.ObjectId, ref: 'Car' },\n  cars: [{ type: Schema.Types.ObjectId, ref: 'Car' }],\n});\n```\n\nYou can just write this:\n\n```ts\nclass Job {\n  @prop()\n  public title?: string;\n\n  @prop()\n  public position?: string;\n}\n\nclass Car {\n  @prop()\n  public model?: string;\n}\n\nclass User {\n  @prop()\n  public name?: string;\n\n  @prop({ required: true })\n  public age!: number; // This is a single Primitive\n\n  @prop({ type: () =\u003e [String] })\n  public preferences?: string[]; // This is a Primitive Array\n\n  @prop()\n  public mainJob?: Job; // This is a single SubDocument\n\n  @prop({ type: () =\u003e Job })\n  public jobs?: Job[]; // This is a SubDocument Array\n\n  @prop({ ref: () =\u003e Car })\n  public mainCar?: Ref\u003cCar\u003e; // This is a single Reference\n\n  @prop({ ref: () =\u003e Car })\n  public cars?: Ref\u003cCar\u003e[]; // This is a Reference Array\n}\n```\n\n[Extra Examples](https://typegoose.github.io/typegoose/docs/guides/quick-start-guide#extra-examples)\n\n---\n\n## Requirements \u0026 Install\n\n[Typegoose's Quick Start Guide](https://typegoose.github.io/typegoose/docs/guides/quick-start-guide)\n\n## Testing\n\n```sh\nyarn install\nyarn run test\n```\n\n## Versioning\n\nThis Project should comply with [Semver](https://semver.org). It uses the `Major.Minor.Fix` standard (or in NPM terms, `Major.Minor.Patch`).\n\n## Join Our Discord Server\n\nTo ask questions or just talk with us, [join our Discord Server](https://discord.gg/BpGjTTD).\n\n## Documentation\n\n* [Typegoose Documentation](https://typegoose.github.io/typegoose/docs/api/index-api)\n* [Quick start guide](https://typegoose.github.io/typegoose/docs/guides/quick-start-guide/)\n\n## Known Issues\n\n[Here are the known-issues](https://typegoose.github.io/typegoose/docs/guides/known-issues/)\n\n## FAQ\n\n[Here is the FAQ](https://typegoose.github.io/typegoose/docs/guides/faq/)\n\n## Notes\n\n* Please don't add `+1` or similar comments to issues. Use the reactions instead.\n","funding_links":["https://opencollective.com/typegoose"],"categories":["TypeScript","Repository"],"sub_categories":["Database"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftypegoose%2Ftypegoose","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftypegoose%2Ftypegoose","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftypegoose%2Ftypegoose/lists"}