From 647d26db855118f82900bbea75780a27ad16e15f Mon Sep 17 00:00:00 2001 From: Arash <38922203+arashsheyda@users.noreply.github.com> Date: Sun, 9 Jul 2023 13:53:11 +0300 Subject: [PATCH] docs(utils): add hooks and improve documentation --- docs/content/2.api/1.utils.md | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/docs/content/2.api/1.utils.md b/docs/content/2.api/1.utils.md index 36b5cdc..18a56fc 100644 --- a/docs/content/2.api/1.utils.md +++ b/docs/content/2.api/1.utils.md @@ -12,12 +12,16 @@ 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,11 +31,14 @@ 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) => { }) ``` @@ -39,6 +46,16 @@ This function creates a new Mongoose model with schema. Example usage: :: +| **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) => 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).