Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"Error: MongooseError: Operation `users.insertOne()` buffering timed out after 10000ms",

I'm running MongoDB Atlas on node express and I got this error when I tested with postman.

const express = require('express');
const cors = require('cors');
const mongoose = require('mongoose');

require('dotenv').config();

const app = express();
const port = process.env.PORT || 5000;

app.use(cors());
app.use(express.json());

const uri = process.env.ATLAS_URI;
mongoose.connect(uri, { useNewUrlParser: true, useCreateIndex: true }
);
const connection = mongoose.connection;
connection.once('open', () => {
  console.log("MongoDB database connection established successfully");
})

const exercisesRouter = require('./routes/exercises');
const usersRouter = require('./routes/users');

app.use('/exercises', exercisesRouter);
app.use('/users', usersRouter);

app.listen(port, () => {
    console.log(`Server is running on port: ${port}`);
});

This is my .env, I'm guessing the problem might be here too, Kindly help:

ATLAS_URI=mongodb+srv://userone:[email protected]/<dbname>?retryWrites=true&w=majority
like image 618
Clinton Avatar asked Jan 12 '21 09:01

Clinton


1 Answers

In my case, I had to go to Atlas, and reset my whitelisted IP to the correct address.

Then I restarted my local server and tried posting again on postman... And it worked!

like image 63
Bassey Rhema Avatar answered Sep 22 '22 19:09

Bassey Rhema