I'm trying to connect to a MongoDB cluster from VSCode, in the connection string I'm using the correct username and the password that I auto-generated for the database user. I've also tried adding my current IP to the IP whitelist as well the access from anywhere global IP option. The error I got before this one read something like the IP address needs to be added to the IP whitelist.
This is the server configuration:
const express = require('express');
const { json } = require('express');
const authRoutes = require('./routes/auth');
const cors = require('cors');
const morgan = require('morgan');
const mongoose = require('mongoose');
const dotenv = require('dotenv');
dotenv.config();
const app = express();
app.use(express.json()); //alternative to body-parser
// connect to db
mongoose.connect(process.env.DATABASE, {
useNewUrlParser: true,
useFindAndModify: false,
useUnifiedTopology: true,
useCreateIndex: true
})
.then(() => console.log('DB connected'))
.catch(err => console.log('DB connection ERROR: ', err));
// morgan allows us to get server side feedback for each router/request.
app.use(morgan('dev'));
// use cors module to define accepted request sources
if (process.env.NODE_ENV = 'development') {
app.use(cors({ origin: `http://localhost:3000` }))
}
// middleware
app.use('/api', authRoutes);
const port = process.env.PORT
app.listen(port, () => console.log(`Server listening on port ${port} - ${process.env.NODE_ENV}`));