divyansh dahiya
divyansh dahiya

Reputation: 45

MongooseError: Operation users.insertOne() buffering timed out after 10000ms” in Mongo Db atlas

I am currently working with node and mongoDB here is my code

import dotenv from "dotenv";
import mongoose from "mongoose";

dotenv.config();

mongoose
  .connect(
    `mongodb+srv://OmniBotBuilder:${process.env.DBPASS}${process.env.DBUSER}.kx2vg.mongodb.net/${process.env.DBNAME}?retryWrites=true&w=majority`,
    {
      useUnifiedTopology: true,
      useNewUrlParser: true,
    }
  )
  .catch(() => console.error("Unable to connect to DB"));

mongoose.connection.on("connected", () => {});

const Schema = mongoose.Schema;

const omniGamesSchema = new Schema({
  discordId: Number,
  steamId: Number,
});

const omniGamesModel = mongoose.model("omniGamesSchema", omniGamesSchema);

const createNewUser = (discordId, steamId) => {
  const newUserMap = new omniGamesModel({
    discordId: discordId,
    steamId: steamId,
  });

  newUserMap.save((err) => {
    if (err) {
      console.error(err);
    }
  });
};

export { createNewUser };

and the error i am getting is this one enter image description here

MongooseError: Operation omnigamesschemas.insertOne() buffering timed out after 10000ms at Timeout. (C:\Users\dahiy\OneDrive\Desktop\bots\omni-games\node_modules\mongoose\lib\drivers\node-mongodb-native\collection.js:198:23) at listOnTimeout (node:internal/timers:557:17) at processTimers (node:internal/timers:500:7)

Upvotes: 3

Views: 12555

Answers (2)

jatin.rathod
jatin.rathod

Reputation: 61

  1. You can open https://cloud.mongodb.com/
  2. Click connect Goto the Connect your application
  3. Select Driver Node.js version 4.1 leter
  4. Copy the link which you have to show than paste this link to your project .env file now try to run application connect Database and check.

Upvotes: 0

UltraX
UltraX

Reputation: 379

This issue normally is caused because:

  • wrong auth, by the meaning the mongo path string is wrong so maybe double check your pass and username

  • check the allowed IP to access the database from the mongo website, if you want it to be accessed from everywhere just use IP: 0.0.0.0/0

  • Your internet connection might be slow to the point it cannot connect to the DB

Hope you found this helpful! :)

Upvotes: 3

Related Questions