UnhandledPromiseRejectionWarning: MongooseServerSelectionError

后端 未结 3 540
梦谈多话
梦谈多话 2020-11-28 16:23

I am following these tutorials as I wanted to start with MongoDB and the MERN stack:

  • https://medium.com/@beaucarnes/learn-the-mern-stack-by-building-an-exercis
相关标签:
3条回答
  • 2020-11-28 17:04

    Try this It seems like you are using MongoDB atlas

    mongoose
         .connect( uri, { useNewUrlParser: true, useCreateIndex: true, useUnifiedTopology: true })
         .then(() => console.log( 'Database Connected' ))
         .catch(err => console.log( err ));
    

    and go to your MongoDB Atlas -> NetworkAccess-> Edit-> and add Current IP address it works!!

    0 讨论(0)
  • 2020-11-28 17:05

    Try this

    mongoose.connect(uri, {
          useNewUrlParser: true,
          useCreateIndex: true,
          useUnifiedTopology: true
        }).then(res=>{
                console.log("DB Connected!")
        }).catch(err => {
          console.log(Error, err.message);
        })
    
    0 讨论(0)
  • 2020-11-28 17:09

    I understood you error as I also faced it will trying to connect to mongoDB.

    This error is simply popping up because your mongoDB local server failed to connect to remote server probably because you don't shut down the file correctly.

    How to fix:

    1. Go to cmd prompt and change dir to mongo bin file like this (c:\program files\mongodb\server\4.2\bin).
    2. Now type mongo and hit enter, you will see error not able to connect to mongodb server.
    3. Now go to task manager.
    4. Go to services tab.
    5. Find mongodb and select it.
    6. Now open the open service tab at bottom of same screen.
    7. Again search for mongodb server and select it.
    8. Now click the green play button saying start service.

    That's it , your mongodb server is running again. You can check again in cmd prompt by typing same command.

    0 讨论(0)
提交回复
热议问题