Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to connect to mongoDB Atlas using mongoose

Tags:

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?.

like image 298
M Hilal Avatar asked Apr 13 '17 13:04

M Hilal


People also ask

Can mongoose connect MongoDB Atlas?

We have also looked at how to establish a database connection and how to create a schema for our collections. Mongoose can be used to connect to both MongoDB and MongoDB Atlas to your Node.

How do we connect mongoose to our MongoDB database?

You can connect to MongoDB with the mongoose.connect() method. mongoose.connect('mongodb://localhost:27017/myapp'); This is the minimum needed to connect the myapp database running locally on the default port (27017). If connecting fails on your machine, try using 127.0.0.1 instead of localhost .

Can I use MongoDB and mongoose together?

Connecting to MongoDBjs file and use Mongoose to connect to MongoDB. You could connect to a local MongoDB instance, but for this article we are going to use a free MongoDB Atlas cluster. If you don't already have an account, it's easy to sign up for a free MongoDB Atlas cluster here.


1 Answers

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);
    
like image 113
eljefedelrodeodeljefe Avatar answered Oct 25 '22 01:10

eljefedelrodeodeljefe