52 lines
1.1 KiB
Markdown
52 lines
1.1 KiB
Markdown
# Utils
|
|
|
|
Discover all available utils.
|
|
|
|
## `defineMongooseModel`
|
|
|
|
This function creates a new Mongoose model with schema. Example usage:
|
|
|
|
::code-group
|
|
|
|
```ts [named parameters]
|
|
export const User = defineMongooseModel({
|
|
name: 'User',
|
|
schema: {
|
|
name: {
|
|
type: String,
|
|
required: true,
|
|
},
|
|
},
|
|
options: {
|
|
|
|
},
|
|
})
|
|
```
|
|
|
|
```ts [positional parameters]
|
|
import { defineMongooseModel } from '#nuxt/mongoose'
|
|
|
|
export const User = defineMongooseModel('User', {
|
|
name: {
|
|
type: String,
|
|
required: true,
|
|
},
|
|
}, {
|
|
|
|
})
|
|
```
|
|
|
|
::
|
|
|
|
|
|
## `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).
|
|
|
|
Example usage:
|
|
|
|
```ts
|
|
import { defineMongooseConnection } from '#nuxt/mongoose'
|
|
|
|
export const connection = defineMongooseConnection('mongodb://127.0.0.1/nuxt-mongoose')
|
|
``` |