Uneasy
Uneasy

Reputation: 1

mongodb,mongoose invalid database but works remotely

I wanted to enable auth and remote acccess. for mongoose I use connect string: mongoose.connect('mongodb://username:password@host:port/database')

It works if I connect remotely with compass, but mongoose.connect returns invalid database name.

However if i remove database name from the string, mongoose connects but to 'test' database and can't perform any action as it has no permissions (my user only have permission to certain database).

I really don't understand why is that happening.

Upvotes: 0

Views: 1576

Answers (1)

anhlc
anhlc

Reputation: 14449

You have to specify the database name where username is stored

For example if user is in database

mongoose.connect('mongodb://username:password@host:port/database?authSource=database')

If user is in admin database:

mongoose.connect('mongodb://username:password@host:port/database?authSource=admin')

Upvotes: 2

Related Questions