Closed shine977 closed 3 years ago
// app.module.ts import { Module, } from '@nestjs/common'; import * as path from 'path'; import { AppController } from './app.controller'; import { AppService } from './app.service'; import { ComponentModule } from './modules/component/component.module'; import { PageModule } from './modules/page/page.module'; import { FieldModule } from './modules/field/field.module'; import { V2Module } from './modules/v2/v2.module'; import { MongooseModule } from '@nestjs/mongoose'; import { ConfigModule, ConfigService } from 'nestjs-config'; @Module({ controllers: [AppController,], providers: [AppService,], imports: [ComponentModule, PageModule, FieldModule, V2Module, ConfigModule.load(path.resolve(__dirname, 'config', '**/!(*.d).{ts,js}')), MongooseModule.forRootAsync({ imports: [ConfigModule], useFactory: async (configService: ConfigService) => { return configService.get('database') }, inject: [ConfigService] }) ] }) export class AppModule { }
{ auto_reconnect: true, useNewUrlParser: true, useFindAndModify: false, uri: 'mongodb://1xx.x.x.1:27017,1x.x.x.1:27017,1x.x.x.1:27017/database', user: 'user', pass: 'pass', replset: 'set' }
https://mongoosejs.com/docs/connections.html#replicaset_connections
mongoose.connect('mongodb://user:pw@host1.com:27017,host2.com:27017,host3.com:27017/testdb');
I can connect each database separately, but according to the mongoose example above, the connection keeps failing. What should I do? tanks!
Nest version: latest For Tooling issues: - Node version: latest - Platform: Macos 10.15.7 Others:
Please, use our Discord channel (support) for such questions. We are using GitHub to track bugs, feature requests, and potential improvements.
I'm trying to conenct mongo replicat set,but until retrying ....
Input Code
configService.get('database') executed result
Mongoose example
https://mongoosejs.com/docs/connections.html#replicaset_connections
Minimal reproduction of the problem with instructions
What is the motivation / use case for changing the behavior?
I can connect each database separately, but according to the mongoose example above, the connection keeps failing. What should I do? tanks!
Environment