# nest-typegoose

> Nest.js wrapper for @typegoose/typegoose

Latest version **1.1.1** (published 2023-06-29) · MIT license · 0 weekly downloads

## Install

```sh
npm install nest-typegoose
pnpm add nest-typegoose
yarn add nest-typegoose
bun add nest-typegoose
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.1 |
| Published | 2023-06-29 |
| First published | 2022-07-23 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 3 |
| Unpacked size | 172.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Hirasawa Ishikawa |
| Maintainers | hirasawa_au |

## Links

- npm: https://www.npmjs.com/package/nest-typegoose
- Issues: https://github.com/hirasawaau/nest-typegoose/issues
- npm.io page: https://npm.io/package/nest-typegoose

## Dependencies (3)

- [rxjs](https://npm.io/package/rxjs.md) 7.5.6
- [rimraf](https://npm.io/package/rimraf.md) 3.0.2
- [reflect-metadata](https://npm.io/package/reflect-metadata.md) 0.1.13

## Recent versions

- 1.1.1 (latest) — 2023-06-29
- 1.1.0 — 2023-05-01
- 1.0.4 — 2022-09-24
- 1.0.3 — 2022-08-18
- 1.0.2 — 2022-07-24
- 1.0.1 — 2022-07-24
- 1.0.0 — 2022-07-23

## README

# nest-typegoose
Nestjs' wrapper for `@typegoose/typegoose` that inspired from [@nestjs/mongoose](https://github.com/nestjs/mongoose)

## Example
### Initialize Module


```typescript
// app.module.ts
import { TypegooseModule } from 'nest-typegoose'

@Module({
  import: [ 
    TypegooseModule.forRoot('mongodb://<your-uri>' , options)
  ]
})
export class AppModule {}
```

### Model Injection

#### Model Example
```typescript
// cat.model.ts
@modelOptions({
  options: {
    customName: 'cats',
  },
})
export class CatModel {
  @prop({ auto: true })
  id: Types.ObjectId

  @prop()
  name: string
}
```

#### Initialize Model to Module 
```typescript
// cat.module.ts
import { Module } from '@nestjs/common'
import { CatModel } from './cat.model'

@Module({
  imports: [TypegooseModule.forFeature([CatModel])],
  provider: [...],
  exports: [...],
})
export class CatModule {}
```

#### Inject Model to Service
```typescript
import { Injectable } from '@nestjs/common'
import { CatModel } from './cat.model'
import { InjectModel } from 'nest-typegoose'
import { ReturnModelType } from '@typegoose/typegoose'

@Injectable()
export class CatService {
  constructor(@InjectModel(CatModel) private readonly catModel: ReturnModelType<typeof CatModel>) {}

  ...
}
```

```

---
_Source: https://npm.io/package/nest-typegoose · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
