I am trying to connect to my Mongo cluster using a connection string like this:
module.exports = {
MongoURI: MongoURI: 'mongodb+srv://philip:DummyPassword9$@test-cluster-026fd.mongodb.net/test?retryWrites=true'
}
And have set my configuration in the app.js:
const express = require('express');
const expressLayouts = require('express-ejs-layouts');
const mongoose = require('mongoose');
const app = express();
// DB Config
const db = require('./config/keys').MongoURI;
// Connect to Mongo
mongoose.connect(db, { useNewUrlParser: true })
.then(() => console.log('MongoDB Connected....'))
.catch(err => console.log(err));
//EJS
app.use(expressLayouts);
app.set('view engine', 'ejs');
// Routes
app.use('/', require('./routes/index'));
app.use('/users', require('./routes/users'));
const PORT = process.env.PORT || 5000;
app.listen(PORT, console.log(`Server started on port ${PORT}`));
But instead of connecting to the Mongo cluster I get an error:
MongoError: authentication fail
I read everything that I could find online related to this problem, I tried encoding my password like this:
module.exports = {
MongoURI: `mongodb+srv://philip:${encodeURIComponent('DummyPassword9')}$@test-cluster-026fd.mongodb.net/test?retryWrites=true`
}
But still I can't connect and I get this error. I am sure that my account password is right, what am I doing wrong?