1

I think there is a very simple answer to this but I've run into this issue twice now. I have my connection string as: "mongodb+srv://USERNAME:PASSWORD@cluster0.ehf5z.mongodb.net/DATABASENAME?retryWrites=true&w=majority"

I've entered my USERNAME and PASSWORD, but what do I enter for DATABASENAME? I know it seems obvious that I should enter the name of my database, but I don't see anything that literally says Database on my mongoDB-atlas project. I've entered my project name but it does not work and the tutorials I see on YouTube all vary just enough to not give me a clear answer to this seemingly simple question.

bgardne7
  • 91
  • 1
  • 11

2 Answers2

1

In your Atlas panel, in the Clusters section of your project, click on this button: enter image description here

It will give you a list of your databases. If you have not created a database yet, click "Create Database"

enter image description here

codemonkey
  • 7,325
  • 5
  • 22
  • 36
  • That definitely answers my question thank you. I guess I knew that but ran into an issue of "Authentication Failed" for a different reason thinking it was this reason. I will mark the question as answered but it seems the reason for that error was that I set my network access for that project to "add my ip address" rather than "allow access from anywhere". Why would that selection lead to an error in connecting to the database? Once I changed it to "allow access from anywhere" it worked and connected just fine. – bgardne7 Feb 18 '21 at 20:04
  • If i have you `USERNAME` and `PASSWORD`, i will be able to access your database, because you have "allow access from anywhere", in the other hand if you specifi a certaing ip address, i wont be able to connect. – Haniel Baez Feb 18 '21 at 20:10
  • right, so why was I receiving "Authentication Failed" from my computer when I selected "add my IP address" but receiving a successful connection when I selected "allow access from anywhere"? It seems that my error all along was from the selection of "add my IP address" – bgardne7 Feb 18 '21 at 20:38
  • @bgardne7 hard to tell without looking at your Atlas network settings. I can say, though, that when I set my home address as whitelisted, it always works. In your Atlas Network Access, do you see this line: `xx.xx.xx.xx/32 (includes your current IP address) ` where xx.xx.xx.xx is your home IP? – codemonkey Feb 18 '21 at 22:11
0

MongoDB authenticate at database level, so you root user should be authenticated at the admin database.

"mongodb+srv://USERNAME:PASSWORD@cluster0.ehf5z.mongodb.net/admin?retryWrites=true&w=majority"

Why database level? Because a user can have privileges across different databases; that is, a user’s privileges are not limited to their authentication database.

Haniel Baez
  • 1,646
  • 14
  • 19