A Nuxt module for simplifying the use of Mongoose in your project.

A Nuxt module for simplifying the use of Mongoose in your project.
pnpm add nuxt-mongoose
Add nuxt-mongoose to the modules section of your nuxt.config.ts file.
export default defineNuxtConfig({
modules: [
'nuxt-mongoose',
],
})
You can configure the module by adding a mongoose section to your nuxt.config file.
export default defineNuxtConfig({
mongoose: {
uri: 'process.env.MONGODB_URI',
options: {},
modelsDir: 'models',
},
})
by default, nuxt-mongoose will auto-import your schemas from the models directory from server directory. You can change this behavior by setting the modelsDir option.
This function creates a new Mongoose connection. Example usage:
import { defineMongooseConnection } from '#nuxt/mongoose'
export const connection = defineMongooseConnection('mongodb://127.0.0.1/nuxt-mongoose')
This function creates a new Mongoose model with schema. Example usage:
import { defineMongooseModel } from '#nuxt/mongoose'
export const User = defineMongooseModel('User', {
name: {
type: String,
required: true,
},
})
undefinedor you could use it like:undefined
export const User = defineMongooseModel({
name: 'User',
schema: {
name: {
type: String,
required: true,
},
},
})
We use cookies
We use cookies to analyze traffic and improve your experience. You can accept or reject analytics cookies.