Updated March 8, 2023
Definition of MongoDB Web Interface
MongoDB web interface is a tool used to administrate our database server via the web browser, there are multiple web interface tools available in MongoDB. There is multiple features of the web interface in MongoDB like we can create database and collection by using the web interface. We can also use the web interface GUI tool to monitor the MongoDB database server, there are multiple MongoDB web interface GUI tools available like Studio 3T, Robo 3T, NoSQL booster, DB Schema, MongoDB monitoring tools, and NoSQL manager. This tool is used to improve the productivity of DBA and development tasks.
Syntax
Below is the syntax of web interface in MongoDB.
1) Connect to the database cluster using MongoDB compass –
mongodb+srv://database_username:<user_password>@hostname/database_name
2) Connect to the database cluster using MongoDB shell –
mongo "mongodb+srv://hostname/database_name" –database_username <name of user>
Parameters:
1) Mongodb – This parameter is used to connect the MongoDB database cluster using the MongoDB compass. We can connect MongoDB compass by using the mongodb command, we can also pass the username, hostname, and password at the time of connecting to the database server.
2) Database username – This is defined as a username that was used to connect the database server. We need to give specified privileges on the database to the user for performing the task.
3) User password – This is defined as the user password which was used to authenticate a user with the database server. We need to specify the correct username password for connecting to the database server.
4) Hostname – This is defined as the name of the user who was used to connect to the database server. We can use either hostname or database server IP for connecting to the database server.
5) Database name – This is defined as the name of the database which was used with the connection string to connect the database server. I suppose we have used the database name at the time of connection string it will connect to the specified database.
6) Mongo – This is a command in MongoDB which was used to connect to the database server. We can connect to the database server by using the mongo command.
How does the web interface work in MongoDB?
- We can connect the MongoDB database server by using the web interface, there are multiple web interface tools available to connect the database server.
- To connect the MongoDB compass web interface we need to encode our database user password, without encoding it will not accept the database password.
- If we have provided a password in plain text format then it will not accept the password. It will show an error.
- The below example shows that we need to encode a password before using this into the connection string using MongoDB compass.
- In the below example, we have used a connection string for connecting to the database server. We have used username as dbuser and password as Mongodb@123.
- But we have used this password in plain text format so it will show the error at the time of login into the database server.
Code:
mongodb+srv://dbuser:Mongodb@[email protected]/test
Figure – we need to encode password before using this into the connection string using MongoDB compass.
- We need to convert the following characters from plain text to encoding format at the time of using this password in MongoDB compass.
: / ? # [ ] @
- If suppose our password contains any of the above letters then we need to convert the same into encoding format.
- For example, if suppose our database user password is “Mongodb@123” the encoded password is “Mongodb%40123”.
- After connecting to the MongoDB compass web interface we can create a database and collection using the GUI interface.
- There are multiple tools available in MongoDB to connect the MongoDB database server.
- MongoDB compass is the real-time web interface for the database user, using MongoDB compass we can real-time access our database server.
- Using MongoDB atlas cluster we can also connect from the MongoDB shell using the mongo command.
Examples
The below example shows the web interface in MongoDB.
1) MongoDB web interface connects the MongoDB atlas cluster via MongoDB shell
- The below example shows that MongoDB web interface connects the MongoDB atlas cluster via MongoDB shell.
- We have connected to the “cluster0.xttyr.mongodb.net” host by using the user as dbuser. We can see that we are connected to the “cluster0.xttyr.mongodb.net” host which was hosted on the MongoDB atlas cluster.
Code:
mongo "mongodb+srv://cluster0.xttyr.mongodb.net/myFirstDatabase" --username dbuser
show dbs
use local
show collections
Figure – Example of MongoDB web interface connect to the MongoDB atlas cluster via MongoDB shell.
In the above example, we have connected to the database cluster after connecting to the cluster we have to use a local database and display the collections from a local database.
2) MongoDB web interface connects to the database cluster via MongoDB compass
The below example shows that MongoDB web interface connects to the database cluster via MongoDB compass.
We have connected to the “cluster0.xttyr.mongodb.net” host by using the user as dbuser and the password as “Mongodb@123”. We have encoded the given password before use into the MongoDB compass.
We can see that encode format of “Mongodb@123” password is “Mongodb%40123”.
Code:
mongodb+srv://dbuser:Mongodb%[email protected]/test
Figure – Example of MongoDB web interface connect to the database cluster via MongoDB compass.
3) Create the database in MongoDB web interface by using MongoDB compass
The below example shows that create the database and collection in MongoDB web interface by using MongoDB compass.
- To create the database first click on create a database, after clicking on create database need to give the database name and collection name.
- After giving a specified database and collection name click on create a database. After clicking create a database we can see that the specified database is created and we can see the same in the dashboard.
- We have created a database name as MongoDB and a collection name as collection_test.
Code:
MongoDB Dashboard -> Create database -> Give database name and collection name -> click on create database.
Figure – Example of creating the database and collection in MongoDB web interface by using MongoDB compass.
Conclusion
MongoDB compass is the real-time web interface tool used in MongoDB to monitor the database and application. We can create the database and collection by using MongoDB compass. We can connect the MongoDB atlas cluster by using the MongoDB shell and mongo command.
Recommended Articles
This is a guide to MongoDB Web Interface. Here we discuss the Introduction, How does the web interface work in MongoDB? and examples respectively. You may also have a look at the following articles to learn more –