0

I'm currently learning MongoDB, and I'm trying to connect to my database by MongoDB ATLAS but I'm getting trouble which I couldn't yet connect to it

here is the code:

    mongoose.connect('mongodb+srv://anis:anisninis@cluster.mongodb.net/',
    { 
        dbName: 'testDB',
        useNewUrlParser: true,
        useUnifiedTopology: true
    })
    .then(() => console.log('Connexion à MongoDB réussie !'))//you are connected
    .catch(() => console.log('Connexion à MongoDB échouée !'));// you aren't

the output: you are not connected to MongoDB

Anatoly
  • 20,799
  • 3
  • 28
  • 42
66 77
  • 9
  • 1
  • sorry ! but i didn't understand what you mean can you please explain more – 66 77 Nov 29 '20 at 22:07
  • Welcome to Stack Overflow! The error is coming from the commands **after** the shown code, because nothing is blocking up to then ;-) Try `await mongoose.connect(...)`. Also if those are your real credentials, you should change them by now. – Daniel W. Nov 29 '20 at 22:10
  • here is the url : mongodb+srv://anis:@cluster0.knyha.mongodb.net/?retryWrites=true&w=majority so i don"t know my dbname so i followed this one https://stackoverflow.com/questions/48917591/fail-to-connect-mongoose-to-atlas/48917626#48917626 – 66 77 Nov 29 '20 at 22:20

0 Answers0