arashsheyda / nuxt-mongoose

A Nuxt module for simplifying the use of Mongoose in your project.
https://docs.arashsheyda.me/nuxt-mongoose
75 stars 13 forks source link

Request for help #65

Open Ena-Heleneto opened 1 week ago

Ena-Heleneto commented 1 week ago

Hello,My project needs to connect to multiple databases simultaneously. Is there a way to quickly create multiple connections?

arashsheyda commented 1 week ago

you can use defineMongooseConnection to create connection

Ena-Heleneto commented 1 week ago

Sorry, I don't quite understand. I want to establish a persistent database connection. Where should I execute it? like this?

//utils/db.util.ts
import { defineMongooseConnection } from '#nuxt/mongoose'

export const connection01 = defineMongooseConnection({ uri: 'mongodb://127.0.0.1/nuxt-mongoose01' })
export const connection02 = defineMongooseConnection({ uri: 'mongodb://127.0.0.1/nuxt-mongoose02' })
  //nuxt.config.ts    ~note or delete

  // mongoose: {
  //   uri: 'mongodb://root:root%4012138@8.219.6.234:27017/',
  //   options: {},
  //   modelsDir: 'models',
  //   devtools: true,
  // },

Will this create a new database connection each time it's called?

Or I think the multi-connection configuration method in NestJS is quite good, maybe can use it as a reference. https://docs.nestjs.com/techniques/mongodb#multiple-databases