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

Mongoose: auth against admin database but connect to another #878

Closed
MarkusAnthony opened this issue Dec 10, 2019 · 2 comments
Closed

Mongoose: auth against admin database but connect to another #878

MarkusAnthony opened this issue Dec 10, 2019 · 2 comments

Comments

@MarkusAnthony
Copy link

I'm submitting a...


[ ] Regression 
[ ] Bug report
[ ] Feature request
[ X ] Documentation issue or request (new chapter/page)
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.

Current behavior

I want to authenticate against "admin" database but open another database.

Expected behavior

I would like to specify the database I want to "open" and query against.

Minimal reproduction of the problem with instructions

app.module.ts


import { ConfigService } from './config/config.service';
import { Module } from '@nestjs/common';
import { MongooseModule } from '@nestjs/mongoose';

import { ConfigModule } from './config/config.module';
import { CaseAssetsModule } from './case-assets/case-assets.module';

@Module({
  imports: [
    ConfigModule,
    CaseAssetsModule,
    MongooseModule.forRootAsync({
      imports: [ConfigModule],
      useFactory: async (configService: ConfigService) => ({
        uri: configService.getString('mongodb.uri'),
        useNewUrlParser: true,
        useUnifiedTopology: true,
      }),
      inject: [ConfigService],
    })
  ],
  controllers: [],
  providers: [],
})
export class AppModule { }

Connection string:

mongodb://<>:<>#@<>:27017/admin

What is the motivation / use case for changing the behavior?

Environment


Lastest version of nodejs, nestjs, mongoose

Others:

@galesky
Copy link
Contributor

galesky commented Dec 12, 2019

I think you may have created this issue at the wrong repo, but anyhow, the easiest way is to specify authSource in the uri

const uri = 'mongodb://monguser:mongpass@192.168.1.1:27017/DATABASE?authSource=admin';

If you need more info, see this issue Automattic/mongoose#3905

@kamilmysliwiec
Copy link
Member

Please, use our Discord channel (support) for such questions. We are using GitHub to track bugs, feature requests, and potential improvements.

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

3 participants