Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

233
Visualizações
"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:useronepassword1234@cluster0.swye5.mongodb.net/<dbname>?retryWrites=true&w=majority
over 4 years ago · Santiago Trujillo
15 Respostas
Responde à pergunta

0

  1. First replace <dbname> with your actual DB name, if not created, create one.

  2. Then create collection as required on the Atlas UI itself.

  3. In the Network Access, click on ADD IP ADDRESS and select "allow access from anywhere".

  4. Rewrite your code this way:

mongoose 
 .connect(process.env.MONGO_PROD_URI, {
        useNewUrlParser: true,
        useUnifiedTopology: true,
        useCreateIndex: true,   })   
 .then(() => console.log("Database connected!"))
 .catch(err => console.log(err));
  1. Now your DB should be connected and working fine.

If still not resolved, check this link.

over 4 years ago · Santiago Trujillo Relatório

0

I was facing the same issue. It is resolved. I think you might have not allowed network access to everyone in Atlas: MongoDB. Do it will resolve the issue.

over 4 years ago · Santiago Trujillo Relatório

0

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!

over 4 years ago · Santiago Trujillo Relatório

0

If you are seeing this using Typescript ensure you are importing the connect function from mongoose and use that to connect.

import { connect } from "mongoose";

connect(...).then()
over 4 years ago · Santiago Trujillo Relatório

0

Check your Network Access IP list in MongoDB Cloud.You will only be able to connect to your cluster from the list of IP Addresses

Ensure that your IP Address Setting is Active

over 4 years ago · Santiago Trujillo Relatório

0

Check if you didn't forgot to set password in connection string.

over 4 years ago · Santiago Trujillo Relatório

0

It's kind of late but probably because of this line useCreateIndex: true it's not working. It seems in mongoDB version 5. this is not supported anymore. Rewrite like the answer of manoj_mi5

mongoose
  .connect(process.env.MONGODB_URL, {
      useNewUrlParser: true,
      useUnifiedTopology: true})
  .then(() => console.log("Database connected!"))
  .catch(err => console.log(err));

to check if there are more errors.

over 4 years ago · Santiago Trujillo Relatório

0

Change your MongoDB database-user password. It should be alphanumeric with no special characters. Nothing worked out for me, but, changing the password did.

over 4 years ago · Santiago Trujillo Relatório

0

Step 1:

Go to your Atlas account and open your project.

Step 2:

In the left menu, navigate to Network Access section:

enter image description here

Step 3:

Add your IP Address so only you would be able to connect to your cluster. You can also add 0.0.0.0/0 and it will allow access from everywhere.

over 4 years ago · Santiago Trujillo Relatório

0

I also faced the same error. In my case, the error was coming up because useFindAndModify was set to false in mongoose connection

Code with error

mongoose.connect(dbUrl, { 
    useNewUrlParser: true, 
    useUnifiedTopology: true, 
    useFindAndModify: false 
}, () => { 
    console.log('connected to database myDb ;)') 
})

Working Code

mongoose.connect(dbUrl, { 
    useNewUrlParser: true, 
    useUnifiedTopology: true
}, () => { 
    console.log('connected to database myDb ;)') 
})
over 4 years ago · Santiago Trujillo Relatório

0

"error:MongooseError: Operation users.insertOne() buffering timed out after 10000ms"

mongoose.connect(process.env.MONGO_URL, {
    useNewURLParser: true,
    useUnifiedTopology: true,
    useCreateIndex: true,
  },6000000)

  .then(console.log("connected to server"))
  .catch((err) => console.log(err));

add time like 6000000 after options

over 4 years ago · Santiago Trujillo Relatório

0

In Mongoose version 6 and above don't require those

{    useNewUrlParser: true, 
     useUnifiedTopology: true, 
     useCreateIndex: true, 
     useFindAndModify: false
}

so just delete it. And if you still see app crashed - waiting for file changes before starting... just save it one more time and it will work

over 4 years ago · Santiago Trujillo Relatório

0

In Latest version of mongoose.

we don't require this object.

{ useNewUrlParser: true, useUnifiedTopology: true, useCreateIndex: true, useFindAndModify: false }

But if you are dealing with older versions of mongoose then definetly you need it. Also in your mongodb network address add this address 0.0.0.0/0 in place of your ip address.

over 4 years ago · Santiago Trujillo Relatório

0

in this line of code, ATLAS_URI=mongodb+srv://userone:useronepassword1234@cluster0.swye5.mongodb.net/?retryWrites=true&w=majority

make sure you write actual database name without < > symbols. You have to create your database first in Mongo Atlas. enter image description here

over 4 years ago · Santiago Trujillo Relatório

0

To solve this, I created a function in index.js, where I asynchronically connecting to my Database and then starting the server, because mongoose doesn't wait for db connection it executes everything on spot, form that was the problem.

async function start() {
  try {
    //Database Connect
    await mongoose.connect(
      process.env.DB_CONNECTION,
      {
        useNewUrlParser: true,
        useUnifiedTopology: true,
      },
      () => {
        console.log("Database Connected");
      }
    );

    app.listen(3000, () => {
      console.log("Server is running on port 3000 ...");
    });
  } catch (error) {
    console.error(error);
  }
}
over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda