{"id":13990828,"url":"https://github.com/topfullstack/nestjs-mongoose-crud","last_synced_at":"2025-04-09T18:19:04.055Z","repository":{"id":38751811,"uuid":"213609507","full_name":"topfullstack/nestjs-mongoose-crud","owner":"topfullstack","description":"Nest.js crud module for mongoose models without `nestjsx/crud`","archived":false,"fork":false,"pushed_at":"2023-01-11T22:45:11.000Z","size":685,"stargazers_count":262,"open_issues_count":22,"forks_count":37,"subscribers_count":7,"default_branch":"master","last_synced_at":"2025-04-09T18:18:57.738Z","etag":null,"topics":["crud","mongoose","nestjs","restful-api","typegoose"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/topfullstack.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-10-08T10:07:13.000Z","updated_at":"2025-03-17T07:58:18.000Z","dependencies_parsed_at":"2023-02-09T08:46:06.060Z","dependency_job_id":null,"html_url":"https://github.com/topfullstack/nestjs-mongoose-crud","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/topfullstack%2Fnestjs-mongoose-crud","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/topfullstack%2Fnestjs-mongoose-crud/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/topfullstack%2Fnestjs-mongoose-crud/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/topfullstack%2Fnestjs-mongoose-crud/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/topfullstack","download_url":"https://codeload.github.com/topfullstack/nestjs-mongoose-crud/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248085325,"owners_count":21045139,"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":["crud","mongoose","nestjs","restful-api","typegoose"],"created_at":"2024-08-09T13:03:20.524Z","updated_at":"2025-04-09T18:19:04.038Z","avatar_url":"https://github.com/topfullstack.png","language":"TypeScript","funding_links":[],"categories":["TypeScript"],"sub_categories":[],"readme":"# NestJs + Mongoose CRUD\n\nNest.js crud module for mongoose models **without** `@nestjsx/crud`\n\n## Important\n- NestJs 6.x ----\u003e nestjs-mongoose-crud v1.x\n- NestJs 7.x ----\u003e nestjs-mongoose-crud v2.x\n- fix #7\n\n\u003e Nest.js + Typegoose 中文视频教程请移步哔哩哔哩: [全栈之巅](https://space.bilibili.com/341919508)\n\n## Usage\n1. Install and setup [nestjs-typegoose](https://github.com/kpfromer/nestjs-typegoose#basic-usage) or [nestjs-mongoose](https://docs.nestjs.com/techniques/mongodb)\n1. Install\n    ```shell\n    yarn add nestjs-mongoose-crud\n    # or\n    npm i nestjs-mongoose-crud\n    ```\n1. Import model to module:\n    ```ts\n    import { Module } from '@nestjs/common';\n    import { UsersController } from './users.controller';\n    import { TypegooseModule } from 'nestjs-typegoose';\n    import { User } from './user.model';\n\n    @Module({\n      imports: [\n        TypegooseModule.forFeature([User])\n      ],\n      controllers: [UsersController]\n    })\n    export class UsersModule {}\n    ```\n1. Add `@Crud()` decorator and inject imported model to `model` property.\n    ```ts\n    import { Controller } from '@nestjs/common';\n    import { Crud } from 'nestjs-mongoose-crud'\n    import { User } from './user.model';\n    import { InjectModel } from 'nestjs-typegoose';\n    import { ModelType } from '@typegoose/typegoose/lib/types';\n\n    @Crud({\n      model: User\n    })\n    @Controller('users')\n    export class UsersController {\n      constructor(@InjectModel(User) public model: ModelType\u003cUser\u003e) {}\n    }\n    ```\n\n1. Test your CRUD APIs: http://localhost:3000/users\n\n## APIs\n\ne.g. `@Crud()` for `UsersController`\n\n|METHOD|PATH|DESC|\n|--|--|--|\n|GET|/users|Get all users|\n|GET|/users/:id|Get a user|\n|POST|/users|Create a user|\n|PUT|/users/:id|update a user|\n|DELETE|/users/:id|Delete a user|\n\n\u003e You can find all routes and DTOs by setup [swagger](https://docs.nestjs.com/recipes/swagger)\n\n## Query\nUse a JSON (in string) `query` parameter to find records:\n\n[/users?query={\"where\":{\"username\":\"user1\",\"age\":{\"$gt\":18}},\"sort\":\"-_id\",\"limit\":10,\"page\":2,\"populate\":\"friends\"}]()\n\n## Interfaces\n```ts\nexport interface PaginateKeys {\n  data?: string\n  total?: string\n  lastPage?: string\n  currentPage?: string\n}\n\nexport interface CrudRoute {\n  decorators?: MethodDecorator[]\n}\nexport interface CrudRouteWithDto extends CrudRoute {\n  dto?: any\n  transform?: (data: any) =\u003e any\n}\nexport interface CrudRouteForFind extends CrudRoute {\n  paginate?: PaginateKeys | false\n  limit?: number\n  populate?: string | any\n  sort?: string | any\n  where?: any\n}\nexport interface CrudRouteForFindOne extends CrudRoute {\n  populate?: string | any\n  where?: any\n  select?: any\n}\n\nexport interface CrudRoutes {\n  grid?: false,\n  form?: false,\n  find?: CrudRouteForFind | false,\n  findOne?: CrudRouteForFindOne | false,\n  create?: CrudRouteWithDto | false,\n  update?: CrudRouteWithDto | false,\n  delete?: CrudRoute | false,\n\n}\nexport interface CrudOptions {\n  routes?: CrudRoutes\n}\nexport interface OptionItem {\n  text: string\n  value: string\n}\nexport interface Field {\n  label?: string\n  icon?: string\n  type?: 'hide' | 'text' | 'input' | 'autocomplete' | 'textarea' | 'number' | 'checkbox' | 'checkbox-button' | 'radio' | 'date' | 'dates' | 'week' | 'month' | 'year' | 'daterange' | 'time' | 'datetime' | 'datetimerange' | 'switch' | 'yesno' | 'slider' | 'password' | 'color' | 'select' | 'cascader' | 'transfer' | 'rate' | 'tag' | 'image' | 'button' | 'json-editor' | 'upload-file' | 'image-uploader' | 'tree-select' | 'video-uploader' | 'quill-editor' | 'markdown-editor' | 'bmap' | 'codemirror' | 'gallery'\n  listable?: boolean\n  editable?: boolean\n  attrs?: any\n  layout?: number\n  tip?: string\n  options?: OptionItem[]\n  class?: string | string[]\n  style?: any\n  width?: string | number\n  [key: string]: any\n  column?: Field[]\n}\n\nexport interface Fields {\n  [key: string]: Field\n}\n\nexport interface AvueCrudOption {\n  addBtn?: boolean\n  addRowBtn?: boolean\n  align?: string\n  border?: boolean\n  calcHeight?: number\n  cancelBtnTitle?: string\n  columnBtn?: boolean\n  dataType?: string\n  cellBtn?: boolean\n  dateBtn?: boolean\n  cancelBtn?: boolean\n  dateDefault?: boolean\n  dicData?: any\n  dicMethod?: string\n  dicQuery?: any\n  dicUrl?: string\n  delBtn?: boolean\n  defaultSort?: any\n  dialogFullscreen?: boolean\n  dialogEscape?: boolean\n  dialogClickModal?: boolean\n  dialogCloseBtn?: boolean\n  dialogModal?: boolean\n  dialogTop?: string | number\n  dialogType?: string\n  dialogWidth?: string | number\n  dialogHeight?: string | number\n  defaultExpandAll?: boolean\n  expandRowKeys?: string[]\n  editBtn?: boolean\n  emptyText?: string\n  expand?: boolean\n  expandWidth?: number\n  expandFixed?: boolean\n  excelBtn?: boolean\n  filterBtn?: boolean\n  formWidth?: string | number\n  height?: number\n  header?: boolean\n  index?: boolean\n  indexLabel?: string\n  indexWidth?: number\n  indexFixed?: boolean\n  rowKey?: string\n  indeterminate?: boolean\n  labelWidth?: number\n  maxHeight?: number\n  menu?: boolean\n  menuWidth?: number\n  menuXsWidth?: number\n  menuAlign?: string\n  menuType?: string\n  menuBtnTitle?: string\n  pageSize?: string\n  pageSizes?: number[]\n  printBtn?: boolean\n  refreshBtn?: boolean\n  saveBtn?: boolean\n  updateBtn?: boolean\n  cancalBtn?: boolean\n  saveBtnTitle?: string\n  selection?: boolean\n  selectionWidth?: number\n  selectionFixed?: boolean\n  searchBtn?: boolean\n  selectable?: boolean\n  reserveSelection?: true\n  selectClearBtn?: boolean\n  showHeader?: boolean\n  showSummary?: boolean\n  size?: string\n  sumColumnList?: string[]\n  stripe?: boolean\n  tip?: string\n  tipPlacement?: string\n  title?: string\n  checkStrictly?: boolean\n  updateBtnTitle?: string\n  viewBtn?: boolean\n  width?: number\n  column?: Field[]\n  group?: Field[]\n}\n\nexport interface AvueCrudConfig {\n  option?: AvueCrudOption\n  [key: string]: any\n}\n\nexport interface CrudOptionsWithModel extends CrudOptions {\n  name?: string | string[],\n  model: any\n  fields?: Fields\n  config?: ((instance?: any) =\u003e AvueCrudConfig | Promise\u003cAvueCrudConfig\u003e) | AvueCrudConfig\n}\n\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftopfullstack%2Fnestjs-mongoose-crud","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftopfullstack%2Fnestjs-mongoose-crud","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftopfullstack%2Fnestjs-mongoose-crud/lists"}