2023-04-20 18:16:10 +03:00
2023-04-15 23:10:39 +03:00
2023-04-15 23:10:39 +03:00
2023-04-20 18:16:10 +03:00
2023-04-15 23:10:39 +03:00
2023-04-15 23:10:39 +03:00
2023-04-15 23:10:39 +03:00
2023-04-15 23:10:39 +03:00
2023-04-15 23:10:39 +03:00
2023-04-15 23:10:39 +03:00
2023-04-16 13:27:42 +03:00
2023-04-15 23:10:39 +03:00

nuxt-mongoose

Nuxt Mongoose

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

Installation

pnpm add nuxt-mongoose mongoose

Usage

Setup

Add nuxt-mongoose to the modules section of your nuxt.config.ts file.

export default defineNuxtConfig({
  modules: [
    'nuxt-mongoose',
  ],
})

Configuration

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: {},
  },
})

API

defineMongooseConnection

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')

defineMongooseModel

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,
  },
})

or you could use it like:

export const User = defineMongooseModel({
  name: 'User',
  schema: {
    name: {
      type: String,
      required: true,
    },
  },
})

License

MIT License

Description
A Nuxt module for simplifying the use of Mongoose in your project.
Readme 2.6 MiB
Languages
TypeScript 52.4%
Vue 47.6%