Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
191 views
in Technique[技术] by (71.8m points)

javascript - Cannot connect to mongo db database, showing timeout error

I have created a react app, and I have connected the mongoDB database, now the problem is whenever I start the node server the server gets started as well as the mongodb database, but most of the time the mongoDB database shows timeout error.

I am adding image, have a look through it Qerytxt etimeout errorfor the error as well as I am showing my pacakage.json file.

 {
  "name": "ewk",
  "version": "1.0.0",
  "description": "abcd",
  "main": "server.js",
  "type": "module",
  "scripts": {
    "start": "node backend/server",
    "server": "nodemon backend/server",
    "client": "npm start --prefix frontend",
    "dev": "concurrently "npm run server" "npm run client"",
    "data:import": "node backend/seeder",
    "data:destroy": "node backend/seeder -d"
  },
  "author": "xyz",
  "license": "ISC",
  "dependencies": {
    "bcryptjs": "^2.4.3",
    "dotenv": "^8.2.0",
    "express": "^4.17.1",
    "express-async-handler": "^1.1.4",
    "mongoose": "^5.11.13"
  },
  "devDependencies": {
    "concurrently": "^5.3.0",
    "nodemon": "^2.0.7"
  }
}

This is my database configuration code:

import mongoose from 'mongoose';

const connectDB = async () => {
    try{
        const conn = await mongoose.connect(process.env.MONGO_URI, {
            useUnifiedTopology: true,
            useNewUrlParser: true,
            useCreateIndex: true
        })

        console.log(`MongoDB Connected: ${conn.connection.host}`)
    } catch (error){
            console.error(`Error: ${error.message}`)
            process.exit(1)
    }
}

export default connectDB

I have added the uri which I added in env file:

mongodb+srv://abj:*******@ewfsa-cluster.hbwdr.mongodb.net/EWFSA?retryWrites=true&w=majority

question from:https://stackoverflow.com/questions/66051271/cannot-connect-to-mongo-db-database-showing-timeout-error

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...