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

94
Vistas
Error : Operation users.insertMany() buffering timed out after 10000ms when using mongoose in the following code

I am having a hard time finding an error in this following code i wanted to connect to a database and add some data to it but iam getting an error whose info is specified below

**This is the code of Server.jswhich is the server of the application **

import userdata from './userdata.js';
import data from "./data.js"
import mongoose  from 'mongoose';
import userrouter from './routers/userrouter.js';


const app=express();

mongoose.connect('mongodb://localhost/purpleshades',{
    useNewUrlParser:true,
    useUnifiedTopology:true,
    useCreateIndex:true
})

app.use(express.json());
app.use(express.urlencoded({ extended: true }))

app.use('/api/users',userrouter)
app.use((err,req,res,next)=>{
    res.status(500).send({message:err.message})
})
const port=process.env.PORT || 5000
app.listen(5000,()=>{
    console.log(`serve at http://localhost:${port}`);
})

This is the code of the userserver.js which is the router file of the user router which handles the user many request

import userdata from "../userdata.js";
import User from "../models/usermodel.js";
import expressAsyncHandler from "express-async-handler";

const userrouter=express.Router()

userrouter.get('/seed',expressAsyncHandler( async(req,res)=>{
    const createdusers=await User.insertMany(userdata.users)
    res.send({createdusers})
}))

export default userrouter 

The data file is asfollows which is called userdata.js

const userdata={
    users:[
        {
            name:'Prashanth',
            email:'prashanthyarram@gmail.com',
            password:bcrypt.hashSync('1234',8),
            isadmin:true
        },
        {
            name:'ramesh',
            email:'ramesh@gmail.com',
            password:bcrypt.hashSync('5678',8),
            isadmin:true
        },
        {
            name:'jhon',
            email:'jnonny@gmail.com',
            password:bcrypt.hashSync('91011',8),
            isadmin:true
        },
        {
            name:'cristine',
            email:'cristene@gmail.com',
            password:bcrypt.hashSync('1213',8),
            isadmin:true
        }

    ]
}
export default userdata

Now the error is as follows "message": "Operation `users.insertMany()` buffering timed out after 10000ms"

How do I get rid of this error.

about 4 years ago · Juan Pablo Isaza
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