docs(utils): add hooks and improve documentation

This commit is contained in:
Arash
2023-07-09 13:53:11 +03:00
committed by GitHub
parent 40b8ca91ee
commit 647d26db85

View File

@ -12,13 +12,17 @@ This function creates a new Mongoose model with schema. Example usage:
export const User = defineMongooseModel({
name: 'User',
schema: {
name: {
type: String,
email: {
type: 'string',
required: true,
unique: true,
},
},
options: {
},
hooks(schema) {
},
})
```
@ -27,18 +31,31 @@ This function creates a new Mongoose model with schema. Example usage:
import { defineMongooseModel } from '#nuxt/mongoose'
export const User = defineMongooseModel('User', {
name: {
type: String,
email: {
type: 'string',
required: true,
unique: true,
},
}, {
}, (schema) => {
})
```
::
| **Key** | **Type** | **Require** | **Description** |
| ---------------------------- | ----------- | ----------- | ----- |
| `name` | `string` | true | Name of Model |
| `schema` | `SchemaDefinition` | true | Schema Definition of Model |
| `options` | `SchemaDefinition` | false | Schema Options for Model |
| `hooks` | `(schema: Schema<T>) => void` | false | Schema Hooks Function to customize Model |
## `defineMongooseConnection`
This function creates a new Mongoose connection.
- `nuxt-mongoose` provides a default connection for you, it auto-register a plugin in nitro, so you don't need to use this function unless you want to create a new connection. more info [here](https://github.com/arashsheyda/nuxt-mongoose/blob/main/src/runtime/server/plugins/mongoose.db.ts).