0

'Authentication failed' error on a previously perfectly running MongoDB server hosted on MongoDB Atlas.

I have an instance of MongoDB running in MongoDB cloud. Everything was fine then all of a sudden I get an 'Authentication failed' error.

The funny thing is that this happened before then I changed my password in MongoDB cloud and it worked. How can I solve this permanently?

I am using MongoDB via mongoose in a NextJS app.

YulePale
  • 6,688
  • 16
  • 46
  • 95

1 Answers1

0

Encode the password used, this will solve the issue. I have encoded my password using the https://www.urlencoder.org/

connection_string = 'mongodb+srv://username:encodedpassword@clustername.mongodb.net/?retryWrites=true&w=majority'
# I had to remove the db name from the URL to make this work, so you can set the database name below

# Establish a connection to the MongoDB server

data_collection = mongo(collection="name_of_collection", db="database", url=connection_string)

# Query all documents in the collection
result <- Pacientes_collection$find()
DSDmark
  • 1,045
  • 5
  • 11
  • 25