Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mongoose connection error when using db name in connection string

When I try to connect to Mongo instance using this connection string

mongodb://root:password@localhost:27017/

everything works, however, when I try to specify the database name in the connection string

i.e mongodb://root:password@localhost:27017/storefont

I get the following error MongoDB Connection Error: MongoNetworkError: failed to connect to server [localhost:27017] on first connect [MongoError: Authentication failed.

like image 615
eugenekgn Avatar asked Apr 17 '26 05:04

eugenekgn


1 Answers

Specify the authentication database like this:

mongodb://root:password@localhost:27017/storefont?authSource=admin

If you specify a database then this database is also taken for authentication by default. The MongoDB documentation is not 100% clear in that topic.

See also Authentication failure while trying to save to mongodb

like image 162
Wernfried Domscheit Avatar answered Apr 18 '26 22:04

Wernfried Domscheit



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!