Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Request for help #65

Open
Ena-Heleneto opened this issue Oct 10, 2024 · 2 comments
Open

Request for help #65

Ena-Heleneto opened this issue Oct 10, 2024 · 2 comments

Comments

@Ena-Heleneto
Copy link

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

@arashsheyda
Copy link
Owner

you can use defineMongooseConnection to create connection

@Ena-Heleneto
Copy link
Author

Ena-Heleneto commented Oct 11, 2024

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%[email protected]: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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants