1

When i am trying to connect to my mongodb database with the given script it gives me error that the ip address might be not present there i have added that ip address so it so i choose option from allow all ip address it is also giving error

const express = require('express');
const mongoose = require('mongoose');


const app = express();


const uri = "mongodb+srv://sarang:<pasword####>@maindatabase.zxgjd.mongodb.net/maindatabase?retryWrites=true&w=majority";




const PORT = 7000;
console.log("The server is preparing to run")
mongoose.connect(uri).then(()=>{
    app.listen(PORT,()=>{
        console.log(`Server is running on ${PORT}`)
    })
}).catch(error =>{
    console.log(error.message)
})

and the error is

The server is preparing to run

Could not connect to any servers in your MongoDB Atlas cluster. One common reason is that you're trying to access the database from an IP that isn't whitelisted. Make sure your current IP address is on your Atlas cluster's IP whitelist: https://docs.atlas.mongodb.com/security-whitelist/

enter image description here

sarangkkl
  • 773
  • 3
  • 15
  • 1
    Does this answer your question? [Error : "Could not connect to any servers in your MongoDB Atlas cluster"](https://stackoverflow.com/questions/61937581/error-could-not-connect-to-any-servers-in-your-mongodb-atlas-cluster) – MWO Jan 22 '22 at 10:18
  • 1
    Obviously that doesn't answer as he is allowing access from anywhere using `0.0.0.0`, unless it is in the wrong Atlas account or cluster @MWO. What if you log the full error message i.e `console.log(error.message)` change it to `console.log(error)`? There may be a better description. – Minsky Jan 22 '22 at 10:27
  • i try with mongooseClient it work for me – sarangkkl Jan 22 '22 at 10:56
  • See https://stackoverflow.com/questions/63754742/authentication-failure-while-trying-to-save-to-mongodb/63755470#63755470 – Wernfried Domscheit Jan 22 '22 at 12:46

0 Answers0