How to connect to mongoDB Atlas using mongoose

M Hilal picture M Hilal · Apr 13, 2017 · Viewed 33.1k times · Source

I'm trying to connect to my cluster on mongoDB Atlas via Mongoose.connect(), but every time i try to connect i get an exception "MongoError: authentication fail" I know MongoDB Atlas is new mongo as a service could it be not supported by mongoose yet?.

Answer

eljefedelrodeodeljefe picture eljefedelrodeodeljefe · Jun 14, 2018

The answer in this related post is correct. You should:

  • not mix options with connection string (if done so)
  • make sure your IP you are running on is whitelisted and your network allows connections to Atlas
  • make sure the user has sufficient permissions
  • use the connection string as is provided by atlas and just provide it to

    mongoose.connect(uri);