# RegisterMongoModel

`function` in `plugins` · v0.6.1

<https://docs.seedcord.org/packages/plugins/0.6.1/functions/register-mongo-model>

Associates a Mongoose model with a database service

Creates a Mongoose model from the decorated static schema property and stores it for service registration. The model becomes available as `this.model` in the service. Must be applied to a `public static schema` property in the service class.

```ts
RegisterMongoModel<TService>(
    collection: TService
): <
    SchemaObj extends Record<KeyOfSchema, mongoose.Schema>,
    KeyOfSchema extends keyof SchemaObj & (string | symbol)
>(
    target: SchemaObj,
    propertyKey: KeyOfSchema
) => void
```

Associates a Mongoose model with a database service

Creates a Mongoose model from the decorated static schema property and stores it for service registration. The model becomes available as `this.model` in the service. Must be applied to a `public static schema` property in the service class.

Parameters.

- `collection` `TService` — Collection name for the Mongoose model

Returns `<SchemaObj extends Record<KeyOfSchema, mongoose.Schema>, KeyOfSchema extends keyof SchemaObj & (string | symbol)>(target: SchemaObj, propertyKey: KeyOfSchema) => void`.
