1

I am trying set up a connection with mongo-atlas but its throwing a connection error

Here is my code:

const mongoose = require('mongoose')

const connectionString = 'mongodb+srv://<username>:<password>@nodeexpressproject1.euk9ons.mongodb.net/?retryWrites=true&w=majority'

mongoose
    .connect(connectionString)
    .then(() => console.log('Connected to the DB.....'))
    .catch((err) => console.log(err))

<username and <password are my username and password, respectively.

The error shown is:

MongoNetworkError: failed to connect to server [ac-i4mxecj-shard-00-00.euk9ons.mongodb.net:27017] on first connect [MongoError: bad auth : authentication failed

I have tried basic troubleshooting such as checking IP address

I have checked the following question and no solution works for me Error at connecting to MongoDb Atlas Server

Please note that I don't have any special characters in my password

Ucode2
  • 72
  • 7

1 Answers1

0

Here is your connectionString in place of < username> and < password>, put your username and password, whatever you created at the time of database creation. Your error also says the same "MongoError: bad auth : authentication failed".

Ex. - mongodb+srv://ucode:ucode123@nodeexpressproject1.euk9ons.mongodb.net/?retryWrites=true&w=majority

Rajesh Senapati
  • 201
  • 1
  • 8