This commit is contained in:
Arash Sheyda
2023-07-09 14:08:23 +03:00

View File

@ -12,13 +12,17 @@ This function creates a new Mongoose model with schema. Example usage:
export const User = defineMongooseModel({ export const User = defineMongooseModel({
name: 'User', name: 'User',
schema: { schema: {
name: { email: {
type: String, type: 'string',
required: true, required: true,
unique: true,
}, },
}, },
options: { options: {
},
hooks(schema) {
}, },
}) })
``` ```
@ -27,18 +31,31 @@ This function creates a new Mongoose model with schema. Example usage:
import { defineMongooseModel } from '#nuxt/mongoose' import { defineMongooseModel } from '#nuxt/mongoose'
export const User = defineMongooseModel('User', { export const User = defineMongooseModel('User', {
name: { email: {
type: String, type: 'string',
required: true, 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` ## `defineMongooseConnection`
This function creates a new Mongoose connection. 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). - `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).