Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where do I find my dbname for MongoDB connection string?

Tags:

mongodb

I'm trying to connect my app to mongodb, and I got a connection string from mongodb atlas, requiring me to replace username and password, which I get it, but it also says replace dbname with database name... I never remember I set up a db name, where do I find it? This is the connection string I have:

mongodb+srv://<username>:<password>@cluster0.pfose.mongodb.net/<dbname>?retryWrites=true&w=majority
like image 445
Jeffrey Lee Avatar asked Aug 03 '20 05:08

Jeffrey Lee


People also ask

What is a MongoDB connection string?

MongoDB connection string is defined as connection format to join the MongoDB database server, we have using username, hostname, password, and port parameter to connect the database server. Without a connection string, we cannot connect to the database server, we need a connection string to connect the database server.

How do you see the mongos connection?

To connect to a MongoDB Server using username and password, you have to use 'username@hostname/dbname'. Where username is the username, password is the password for that user, dbname is the database to which you want to connect to and optionally you can specify a port number at which you want to connect to.


2 Answers

By default, the <dbname> is test but to create your own dbname, you need to change the <dbname> to the name of database you're interested to use. MongoDB Atlas will automatically create the db for you based on the name.
For example: Creating a db for Qlabs with username=Que and password=pin123

mongodb+srv://Que:[email protected]/Qlabs?retryWrites=true&w=majority
like image 51
Qudusayo Avatar answered Oct 07 '22 18:10

Qudusayo


For those who wanna create db in with GUI

enter image description here

like image 16
logbasex Avatar answered Oct 07 '22 19:10

logbasex