I have a nest.js node server and I am trying to connect mongoDB data base in the app.module, when the connection string doesn't contains the DB name - the connection to default DB "test" success, but when I specify the DB name- always getting "Authentication failed" error.
app.module.ts:
This works:
imports: [
MongooseModule.forRoot('mongodb://admin:admin@localhost:30000'),
]
But this specifying the DB name failed with Authentication error:
imports: [
MongooseModule.forRoot('mongodb://admin:admin@localhost:30000/test'),
]
or:
imports: [
MongooseModule.forRoot('mongodb://admin:admin@localhost:30000/data'),
]
Using MongoClient directly (without nestjs) connecting successfully:
const client = new MongoClient('mongodb://admin:admin@localhost:30000');
await client.connect();
db = client.db('data');
Any idea what is my problem and what should I do in order to solve this problem?
Thanks.