In this MongoDB Atlas tutorial, you’ll learn how to set up a cluster using the M0 free tier, connect to your cluster through Studio 3T, and import your first collection from a JSON file.
Set up a free MongoDB Atlas cluster
1. Go to the MongoDB Atlas landing page.
2. Fill in the required information (email address, first name, last name, and password).
5. Click the Get started free at the bottom of the form.
6. The website will ask to choose a cluster. Choose Starter Clusters and click on Create a cluster.
You should also receive a welcome email, which confirms that you’re registered with MongoDB Atlas and includes a link for logging onto the service.
7. In the Cloud Provider & Region section, the aws option should be selected as the default provider, but you can select any provider. All three platforms support the free tier.
8. Beneath the list of providers, select a region.
9. Expand the Cluster Tier section and ensure that M0 Sandbox is selected. This is the free M0 service level.
10. Expand the Cluster Name section and type Cluster1 in the text box.
11. Click the Create Cluster button at the bottom of the web page.
12. You should then receive a message stating that your cluster is being created.
When the process is complete, you’ll be taken to the Clusters page, which includes a listing for your new cluster, as shown in the following figure.
The cluster information includes the service level, cloud provider, and region, along with details about operations, connections and logical size, all of which currently show zero amounts.
Configure IP address and connection string
Next, you’ll configure MongoDB Atlas to connect to the cluster you created.
For this, you will need the IP address of the device that will connect to the service.
If you plan to connect to MongoDB Atlas on the same device where you’re setting up the service, MongoDB Atlas can find the local IP address automatically.
As part of this exercise, you’ll also set up an administrator account for accessing the cluster.
You’ll then generate a connection string or Uniform Resource Identifier (URI) based on this account. You’ll be able to use the connection string in Studio 3T, which we’ll use to access MongoDB Atlas.
1. In the Cluster1 section of the Clusters page, click the CONNECT button in the left pane.
The Connect to Cluster1 dialog box appears, showing the two steps you must take to configure your connection.
2. For security reasons, MongoDB Atlas blocks all outside connections by default. In order to connect, you must first whitelist your IP address. In the Step 1 section, do one of the following:
- If you plan to connect from the computer you’re currently using, click Add Your Current IP Address and then click Add IP Address.
- If you plan to connect from a different computer, click Add a Different IP Address, type the IP address, and then click Add IP Address. You can edit the IP address, add IP addresses, or delete them at any time in case you change devices.
3. In the Step 2 section, type admin in the Username text box (or whatever name you want to use), and then type a password in the Password text box.
To make it easier to connect to MongoDB Atlas from Studio 3T, your password should include only alphanumeric characters, that is, letters and numbers only with no special characters.
If you use special characters, you will need to encode them when creating a connection string for accessing the MongoDB service.
4. Click the Create MongoDB User button.
5. The next task is to generate the connection string or Uniform Resource Identifier (URI).
To start this process, click the Choose a connection method button. The Connect to Cluster1 dialog box reappears, providing a different set of options.
6. Click Connect Your Application. You’ll again be presented with two steps.
7. In the Step 1 section, select Java from the DRIVER drop-down list, and select 3.6 or later from the VERSION drop-down list.
These are the settings that Studio 3T requires to connect to MongoDB Atlas.
When you select the driver and version, the service automatically updates the connection string in the Step 2 section.
8. In the Step 2 section, click Copy to copy the connection string to your clipboard, and then paste the connection string to a safe location.
When you use the connection string or URI, you must replace the placeholder with the password you created for the administrator account. Don’t forget to remove the <> as well.
9. Click Close to close the Connect to Cluster1 dialog box, and then sign out of the MongoDB Atlas service.
Connect and import data
1. Open Studio 3T and click on Connect in the top-left corner of the toolbar. This will open the Connection Manager.
2. Click on New Connection in the top-left corner, which will open a new connection window.
3. Name the connection and click on the From URI button.
4. Paste the connection string you copied from MongoDB Atlas.
5. Replace the placeholder “<password>” with your actual password and “<dbname>” with the name of the database that connections will use by default. Make sure to replace the brackets too, and click OK.
Studio 3T will automatically extract the information and pre-populate the fields in the Server, Authentication, SSL, SSH Tunnel, and Advanced tabs. It will also save the connection for later use.
6. Click through the Server, Authentication, SSL, and SSH Tunnel tabs and verify that the information is correct.
7. Click Save. Then click Connect. You should see cluster1 in the Connection Tree.
8. In the Connection Tree, right-click the connection (top-level node) and click Add Database.
3. In the Add Database dialog box, read the information about creating an empty database.
When you create a database in Studio 3T, you’re basically adding a temporary node to the Connection Tree. MongoDB does not create the actual database or its files until you add your first collection.
4. Type pubs in the Database Name text box, and then click OK.
Studio 3T adds the pubs database node to the Connection Tree.
5. Right-click the pubs database node and click Add Collection.
6. In the Add New Collection dialog box, type welsh_pubs in the Collection Name text box, and then click Create.
Do not worry about the other collection settings at this time. Studio 3T opens the welsh_pubs collection tab, which has many parts that you can read more about here.
You can already choose to view your data either in Table, Tree, or JSON View.
7. Download this welsh_pubs.json file and open it in a text editor such as Notepad (Windows) or TextEdit (macOS).
8. In the text editor, copy the entire contents of the file to the clipboard.
9. In Studio 3T, go to the welsh_pubs collection tab, right-click the main document region of the Result tab, and click Paste Document(s).
10. In the Paste Documents dialog box, click OK.
11. When the import process is complete, you should receive a confirmation message stating that 3,122 documents have been imported. Click OK to continue.
12. On the Result tab toolbar, click the Refresh button. The tab should now display the first 50 documents in the result set.
13. At the bottom of the Result tab, click the Count Documents link.
The count should show 3,122 documents. This is a handy tool to know about for verifying the number of documents returned by the current query.
Congratulations! You’ve just set up your free MongoDB Atlas cluster, connected to it via Studio 3T, and created your first collection.
This MongoDB Atlas tutorial is an excerpt from MongoDB 101, the free MongoDB course on Academy 3T. Continue learning the basics of querying, aggregation, working with the mongo shell, and more. Sign up for free here.