Cannot connect to database

I’m trying to connect my API to my MongoDB Atlas database but cannot seem to do it. When I submit a POST request to /products I receive a 201 response, but after a couple of seconds get the following error:
MongooseError: Operation products.insertOne() buffering timed out after 10000ms

Here’s my code for the connection:

const express = require('express');
const app = express();
const morgan = require('morgan');
const bodyParser = require('body-parser');
const mongoose = require('mongoose');

const productRoutes = require('./api/routes/products');
const orderRoutes = require('./api/routes/orders');

mongoose.connect('mongodb://User:' + process.env.MONGO_ATLAS_PASSWORD + ',,', {
useNewUrlParser: true,
useUnifiedTopology: true, 
useCreateIndex: true

app.use(bodyParser.urlencoded({extended: false}));

app.use((req, res, next) => {
res.header('Access-Control-Allow-Origin', '*');
res.header('Access-Control-Allow-Headers', 'Origin, X-Requested-With, Content-Type, Accept, Authorization');
if (req.method == 'OPTIONS') {
    res.header('Access-Control-Allow-Methods', 'PUT, POST, PATCH, DELETE, GET');
    return res.status(200).json({});

// routes which handle requests
app.use('/products', productRoutes);
app.use('/orders', orderRoutes);

app.use((req, res, next) => {
const error = new Error('Uh oh! 404 not found error.');

app.use((error, req, res, next) => {
res.status(error.status || 500);
    error: {
        message: error.message

module.exports = app;

And here’s my code that defines the POST request:

const express = require('express');
const router = express.Router();

const mongoose = require('mongoose');
const Product = require('../models/products');

router.get('/', (req, res, next) => {
    message: 'Handling GET requests to /products'
});'/', (req, res, next) => {
const product = new Product({
    _id: new mongoose.Types.ObjectId(),
    price: req.body.price
.then(result => {
    .catch(err => console.log(err));
    message: 'Handling POST requests to /products',
    createdProduct: product
module.exports = router;

Any ideas on how to fix this/connect to my database? (I know that in my URI string it says MyDatabse, in my actual code I have it set to my database name)

Hi Christian,

Did you ensure that the source IP of your app is on the Atlas IP Access List?