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?.
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.
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 .
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.
The answer in this related post is correct. You should:
use the connection string as is provided by atlas and just provide it to
mongoose.connect(uri);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With