{"id":702,"hash":"a51de72e1f7ba421f027c879859a79958d0c4168de2b93e6cc58f9078d120a40","pattern":"MongooseError - Operation `users.findOne()` buffering timed out after 10000ms","full_message":"My code was working before initially but I don't know why it just stopped working and gave me this error:\n\nMongooseError: Operation `users.findOne()` buffering timed out after 10000ms\n    at Timeout.<anonymous> (/Users/nishant/Desktop/Yourfolio/backend/node_modules/mongoose/lib/drivers/node-mongodb-native/collection.js:184:20)\n    at listOnTimeout (internal/timers.js:549:17)\n    at processTimers (internal/timers.js:492:7)\n\nI am trying to authenticate the user by login with JWT. My client runs fine but in my backend I get this error. My backend code:\n\nimport neuron from '@yummyweb/neuronjs'\nimport bodyParser from 'body-parser'\nimport cors from 'cors'\nimport mongoose from 'mongoose'\nimport emailValidator from 'email-validator'\nimport passwordValidator from 'password-validator'\nimport User from './models/User.js'\nimport Portfolio from './models/Portfolio.js'\nimport bcrypt from 'bcryptjs'\nimport jwt from 'jsonwebtoken'\nimport auth from './utils/auth.js'\n\n// Dot env\nimport dotenv from 'dotenv'\ndotenv.config()\n\n// Custom Password Specifications\n// Username Schema\nconst usernameSchema = new passwordValidator()\nusernameSchema.is().min(3).is().max(18).is().not().spaces()\n\n// Password Schema\nconst passwordSchema = new passwordValidator()\npasswordSchema.is().min(8).is().max(100).has().uppercase().has().lowercase().has().digits().is().not().spaces()\n\nconst PORT = process.env.PORT || 5000\nconst neuronjs = neuron()\n\n// Middleware\nneuronjs.use(bodyParser())\nneuronjs.use(cors())\n\n// Mongoose Connection\nmongoose.connect(process.env.MONGO_URI, { useNewUrlParser: true }, () => console.log(\"MongoDB Connected\"))\n\n// API Routes\nneuronjs.POST('/api/auth/signup', async (req, res) => {\n    const { username, email, password, passwordConfirmation } = req.body\n\n    // Validation: all fields are filled\n    if (!username || !email || !password || !passwordConfirmation) {\n        return res.status(400).json({ \n            \"error\": \"true\",\n            \"for\": \"fields\",\n            \"msg\": \"fill all the fields\"\n        })\n    }\n\n    // Validation: username is valid\n    if (usernameSchema.validate(username, { list: true }).length !== 0) {\n        return res.status(400).json({ \n            \"error\": \"true\",\n            \"for\": \"username\",\n            \"method_fail\": usernameSchema.validate(username, { list: true }),\n            \"msg\": \"username is invalid\"\n        })\n    }\n\n    // Validation: email is valid\n    if (!emailValidator.validate(email)) {\n        return res.status(400).json({ \n            \"error\": \"true\",\n            \"for\": \"email\",\n            \"msg\": \"email is invalid\"\n        })\n    }\n\n    // Validation: password is valid\n    if (passwordSchema.validate(password, { list: true }).length !== 0) {\n        return res.status(400).json({ \n            \"error\": \"true\",\n            \"for\": \"password\",\n            \"method_fail\": passwordSchema.validate(password, { list: true }),\n            \"msg\": \"password is invalid\"\n        })\n    }\n\n    // Validation: password is confirmed\n    if (password !== passwordConfirmation) {\n        return res.status(400).json({ \n            \"error\": \"true\",\n            \"for\": \"confirmation\",\n            \"msg\": \"confirmation password needs to match password\"\n        })\n    }\n\n    // Check for existing user with email\n    const existingUserWithEmail = await User.findOne({ email })\n    if (existingUserWithEmail)\n        return res.status(400).json({ \"error\": \"true\", \"msg\": \"a user already exists with this email\" })\n\n    // Check for existing user with username\n    const existingUserWithUsername = await User.findOne({ username })\n    if (existingUserWithUsername)\n        return res.status(400).json({ \"error\": \"true\", \"msg\": \"a user already exists with this username\" })\n\n    // Generating salt\n    const salt = bcrypt.genSalt()\n    .then(salt => {\n        // Hashing password with bcrypt\n        const hashedPassword = bcrypt.hash(password, salt)\n        .then(hash => {\n            const newUser = new User({\n                username,\n                email,\n                password: hash\n            })\n            // Saving the user\n            newUser.save()\n            .then(savedUser => {\n                const newPortfolio = new Portfolio({\n                    user: savedUser._id,\n                    description: \"\",\n                    socialMediaHandles: {\n                        github: savedUser.username,\n                        dribbble: savedUser.username,\n                        twitter: savedUser.username,\n                        devto: savedUser.username,\n                        linkedin: savedUser.username,\n                    }\n                })\n\n                // Save the portfolio\n                newPortfolio.save()\n\n                // Return the status code and the json\n                return res.status(200).json({\n                    savedUser\n                })\n            })\n            .catch(err => console.log(err))\n        })\n        .catch(err => console.log(err))\n    })\n    .catch(err => console.log(err))\n})\n\nneuronjs.POST('/api/auth/login', async (req, res) => {\n    try {\n        const { username, password } = req.body\n\n        // Validate\n        if (!username || !password) {\n            return res.status(400).json({ \"error\": \"true\", \"msg\": \"fill all the fields\", \"for\": \"fields\", })\n        }\n\n        const user = await User.findOne({ username })\n        if (!user) {\n            return res.status(400).json({ \"error\": \"true\", \"msg\": \"no account is registered with this username\", \"for\": \"username\" })\n        }\n    \n        // Compare hashed password with plain text password\n        const match = await bcrypt.compare(password, user.password)\n    \n        if (!match) {\n            return res.status(400).json({ \"error\": \"true\", \"msg\": \"invalid credentials\", \"for\": \"password\" })\n        }\n    \n        // Create JWT token\n        const token = jwt.sign({ id: user._id }, process.env.JWT_SECRET)\n        return res.json({ token, user: { \"id\": user._id, \"username\": user.username, \"emai","ecosystem":"npm","package_name":"node.js","package_version":null,"solution":"In my experience this happens when your database is not connected, Try checking out following things -\n\nIs you database connected and you are pointing to the same url from your code.\ncheck if your mongoose.connect(...) code is loading.\n\nI faced this issue where I was running the node index.js from my terminal and mongoose connect code was into different file. After requiring that mongoose code in index.js it was working again.","confidence":0.95,"source":"stackoverflow","source_url":"https://stackoverflow.com/questions/65408618/mongooseerror-operation-users-findone-buffering-timed-out-after-10000ms","votes":90,"created_at":"2026-04-19T04:51:30.408670+00:00","updated_at":"2026-04-19T04:51:30.408670+00:00"}