Javascript |
||
mongoDB
In order to try anything about mongoDB, you need to get access to setup the environment first. You have roughly two options to setup those environment. One is to install the mongoDB in your local PC or your internal server. Another option is to use the mongoDB on cloud. In this note, I will show you about the second option, i.e setting up a mongoDB on cloud called atlas. The reason for this is because it is easier to setup the environment on atlas cloud rather than setting up on local PC.
NOTE : The screenshots shown in this page are captured in Feb 2023 and you may see a little bit different look-and-feel depending on when you visit the site. But I think overall logic would remain same.
Setup an MongoDB Atlas Account
To setup the environment on atlas cloud, you need to register to atlas, but I would not explain about the registration and basic setups. You may easily find many YouTube video for the registration and basic setup. You may check out the video in YouTube section in this note if you don't have your own favorite.
Once you finish registration and have your own account on atlas, the next step is to configure the network access.
Select [Network Access] menu and click on [Add IP Address] button.
If you want to add a specific IP (e.g, IP address of your PC which you want to connect to mongoDB on atlas), hit [ADD CURRENT IP ADDRESS] and it will automatically add the IP address for your PC. NOTE : The IP address added here should be the global IP address of your PC. If you are using IPv4 and check your IP with ipconfig (Windows) or ifconfig (Linux) command on your PC, it is highly likely that you will get the local IP address, not global address. There are many internet sites that can give you the global IP of your PC. For example, you can check out on https://www.myglobalip.com/ . If you hit [ADD CURRENT IP ADDRESS], it automatically get your Global IP and fill it out the field.
If you hit [Confirm] button, you would get the specified IP address registered as below.
If you need to change the IP address for some reason (for example, you are trying to get access to the db in different places which has different global IP), you can change the existing IP (or you can add new IP if you like). If you want to change the IP, hit [EDIT] button
Here you can change the existing IP to a new IP manually or by hitting [ADD CURRENT IP ADDRESS] button
NOTE : If you don't want to bother to change these IP everytime you change places, you can allow any IP to get access to the data base by hitting [ALLOW ACCESS FROM ANYWHERE] button.
If you get the ip registered as below, you can get access to the database anywhere.
Now setup the Data Services for the application program that you are going to use. In my case, I will use nodejs and show you how to configure for it.
Go to [Database --> Data Services] as shown below.
Click on [Connect] button and you will get several options as shown below.
Click on [Connect your application] and select [Driver] and [Version] as per your requirement. Then you will have basic example code and use that sample code as your baseline code in your application.
NOTE : If you want to manipulate the MongoDB from shell commad, click on [Connect with the MongoDB Shell]
Browse the Content of Database
You can check on the list of databases and collections that are already created as shown below. Even if you haven't created any database yourself, there are aready a few databases provided as samples as shown below.
If you want to manipulate the data base using API, you can get the basic interface information as shown here.
Go to [Data API] and you see URL Endpoint information as shown below.
To use the API, you need to get your API Key and should use that key. You can create API Key as shown below
Once you have your key and click on [Test Your API] button and select Cluster->Database->Collection items. Then you will get the sample code to get access to the specified collection.
NOTE : How to test the API ? You can test the API in a few different ways. Check out this note about how to test API.
YouTube
| ||