How to Connect to mLab
mLab is the leading Database-as-a-Service for MongoDB, powering over half a million deployments worldwide. Trusted by companies such as Lyft, Facebook, and Whole Foods. Studio 3T is a graphical user interface and IDE for MongoDB.
Among other things, it allows you to explore your data in a more intuitive way and simplifies complex queries through its query tools.
In this post you will learn
- how to setup a cluster with mLab
- how to connect your mLab database to Studio 3T
- where to go to learn more about working with Studio 3T
Set up a Cloud Cluster
This section will guide you through setting up a free Sandbox. A free Sandbox deployment which offers a single node with 500 MB of storage.
- Click on Create New in the MongoDB Deployments section of your home screen.
- Select a cloud provider and the free Sandbox plan type. Then click on the Continue button.
- Select the region that is closest to you. Then click on the Continue button. Note: For production environments your application and your database should be co-located.
- Enter a name for your database. Then click on the Continue button.
After reviewing your selections click on Submit Order.
Obtain the Connection URI
On your mLab home screen, click on the database you want to connect to (if you have a cluster, you will have to first click on the cluster, and then select the database). At the top of the screen of your database you will see a URI of the form:
mongodb://:@ds012345.mlab.com:12345/database-name or mongodb://:@ds012345-a0.mlab.com:12345,ds112345-a1.mlab.com:12345/?replicaSet=rs-ds112345
You need a username and password to replace the placeholders and within this the string.
To create a user, click on the ‘Users’ tab and click the ‘Add database user’ button. Do not select the ‘Make read-only’ option as you need a user that can write to the database.
Connect to Studio 3T
If you haven’t yet, go ahead and download Studio 3T and install it. You will need the connection URI string from your database in the following steps. It should be of the form:
- Inside Studio 3T, click on Connect in the top left corner of the toolbar.
- Inside the Connection Manager that opens up, click on New Connection in the top left corner of the toolbar.
- Inside the new connection window that opens, give your connection a name. Then click on From URI… in the bottom of the window.
- Paste your connection URI (ensure you replace the placeholders with your username and password) and click on Ok.
- To confirm Studio 3T extracted everything correctly, you can verify the information in the Server, Authentication, and SSL tabs. Once you are satisfied click Save.
- Lastly, select the connection you just created and connect to it.
Now that you are all set up, let’s insert an example dataset:
- Either Copy the dataset into your clipboard or save it as a file.
- Inside Studio 3T, select your database and click on Import and import the JSON dataset either from your clipboard or by selecting the file you saved. If you copied the data from your clipboard be sure to add pokemon as the name of your collection.
- Click on Next twice and then on Start Import.
You now have a sample dataset and you’ll find your new collection located on the left hand side within the Connection Pane. Double-click your new collection and you’ll see the Collection Tab open up with all your collection’s documents. From here you can use the UI to add, edit, view, and delete documents. You also have access to the Visual Query Builder from here.
To explore Studio 3T’s functionality further have a look at the three different ways to view your data or how to build complex queries using drag & drop fields. Our other favorites include the IntelliShell that offers auto-completion as you type and the SQL query tool.
If you’re interested in hearing about other tutorials and MongoDB tips, follow mLab on Twitter @mlab.
Find useful Studio 3T tips and tricks by visiting the Studio 3T knowledge base.