# Model Decorator mongoose class
Module | import { Model } from "@tsed/mongoose" |
---|---|
Source | /packages/mongoose/src/decorators/model.ts |
# Overview
function Model(options?: MongooseModelOptions): (target: any) => void;
# Description
Define a class as a Mongoose Model. The model can be injected to the Service, Controller, Middleware, Converters or Filter with
@Inject
annotation.
# Example
@Model()
export class EventModel {
@Property()
field: string;
}
1
2
3
4
5
2
3
4
5
Then inject the model into a service:
class MyService {
constructor(@Inject(EventModel) eventModel: MongooseModel<EventModel>) {
eventModel.findById().exec();
}
}
1
2
3
4
5
2
3
4
5
# Options
schemaOptions
(mongoose.SchemaOptions): Option to configure the schema behavior.name
(String): model name.collection
(String): collection (optional, induced from model name).skipInit
(Boolean): skipInit whether to skip initialization (defaults to false).
- Session & cookies
- Passport.js
- TypeORM
- Mongoose
- GraphQL
- Socket.io
- Swagger
- AJV
- Multer
- Serve static files
- Templating
- Throw HTTP Exceptions
- Customize 404
- AWS
- Jest
- Seq
- Controllers
- Providers
- Model
- Converters
- Middlewares
- Pipes
- Interceptors
- Authentication
- Hooks
- Injection scopes
- Custom providers
- Custom endpoint decorator
- Testing