Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

329
Vistas
"message": "errorMongooseError: Operation `userinfos.insertOne()` buffering timed out after 10000ms"

I'm currently creating a new API with MongoDB and Express, and I'm currently having this issue "message":

"errorMongooseError: Operation userinfos.insertOne() buffering timed out after 10000ms"

his is the way that I setup my API calls:

const express=require('express');
const router=express.Router();
const Userinfo=require("../Models/Userinfo")

router.get('/',(req,res)=>{
    res.send("we are Post")

});



router.get('/Specic', async(req,res)=>{
    try{
        const data=await Userinfo.find();
        console.log(data);
        res.json(data)
    }
    catch(err)
    {
        res.json({message:err})
    }

})
router.post("/",(req,res)=>{
const test= new Userinfo({
    "Fname":req.body.Fname,
    "Lname":req.body.Lname
});
console.log(test);
test.save().then(data=>{
    res.json(data);
}).catch((err)=>{res.json({message:"error"+err})})
})
module.exports=router;

MoDel Defining like this Userinfo.js

const mongoose=require('mongoose');
/*const PoistSchema=mongoose.Schema({
    Fname:String,
    Lname:String,
    DOB:Date.now()
});*/

const PostSchema=mongoose.Schema({
    Fname:{
        type:String,
        require:true
    },
    Lname:{
        type:String,
        require:true
    },
    DOB:{
        type:String,
        default:Date.now
    },
});

module.exports=mongoose.model("Userinfo",PostSchema)

App.js

const express=require('express');
const app=express();
const mongoose=require('mongoose');
require("dotenv/config");
const bodyParser=require("body-parser")
///Middlewares
//app.use(auth);
app.use(bodyParser.json());
const postroutes=require("./Routes/Posts");
app.use("/post",postroutes)

app.get('/',(req,res)=>{
    res.send("we are om")

})

app.get('/posts',(req,res)=>{
    res.send("we are Post")

})
try {
     mongoose.connect(process.env.DBConnection,{useNewUrlParser: true,
        useUnifiedTopology: true,
        useCreateIndex:true},()=>{
         console.log("Sucess");
     },(error)=>{
         console.log(error);

     });
     console.log("ConnectedZZ")

  } catch (error) {
      console.log(error);
  }
app.listen(3000);

Is there any suggestion to inset and get data.While getting data not getting any error.

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

There can be several reasons for this issue occurred, but let's start with:

As We can read in docs

Mongoose lets you start using your models immediately, without waiting for mongoose to establish a connection to MongoDB. That's because mongoose buffers model function calls internally. This buffering is convenient, but also a common source of confusion. Mongoose will not throw any errors by default if you use a model without connecting.

So it looks like Your model is being called before the connection is established. To handle this error, you should use .catch() or try/catch with async/await.That should solve your problem.


Here You have example code snippet:

(async () => {
  try {
    await mongoose.connect(process.env.DBConnection)
    console.log('MongoDB connected!!');
  } catch (err) {
    console.log('Failed to connect to MongoDB', err);
  }
})()
about 4 years ago · Juan Pablo Isaza Denunciar

0

you can confirm if the DB is correct before calling the DB calls.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda