Exercise 1: Creating a collection from a .json file

In this exercise, you will create a database named pubs and a collection named welsh_pubs. You will then import a set of documents from the welsh_pubs.json file, which contains document data about pubs in Wales.

You can download the welsh_pubs.json file here.

To create the collection

1. Launch Studio 3T and connect to MongoDB Atlas.

You will need a connection string or Uniform Resource Identifier (URI) to connect to MongoDB Atlas. If you haven’t generated a URI, go back to the previous exercise Setting Up MongoDB Atlas to set up an Atlas cluster, and refer to Step 8 of Configuring MongoDB Atlas to get the connection string. Be sure to replace the placeholder in the URI with your actual password.

2. In the Connection Tree, right-click the connection (top-level node) and click Add Database.

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.

Database naming

Studio 3T adds the pubs database node to the Connection Tree.

5. Right-click the pubs database node and click Add Collection.

Add collection pubs

6. In the Add New Collection dialog box, type welsh_pubs in the Collection Name text box, and then click Create.

collection nane

Do not worry about the other collection settings at this time. Studio 3T opens the welsh_pubs collection tab, as shown in the following figure.

Tagged names

The collection tab is divided into two sections.

The top section is the query bar, which provides a form for querying the selected collection. By default, the query bar includes a basic query that returns all documents in the collection. You can minimize the query bar by clicking the arrow to the left of the Query text box.

The bottom section displays the results from query in the query bar when the collection contains data. The section includes three tabs: Result, Query Code, and Explain. For this tutorial, you need to be concerned only with the Result tab.

7. If you haven’t already done so, download the 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).

paste document space

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.

Import document tab

12. On the Result tab toolbar, click the Refresh button (Refresh tab).

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.

Count number

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.

Count number

14. Leave the welsh_pubs collection tab open for the next exercise.

You’ve finished the exercise! Click on Test your skills to review what you’ve learned.

Log in

Log in to your Studio 3T Academy account

Forgot password?

Don't have an account yet? Sign up
Sign up

Start learning MongoDB today. All fields are mandatory.

By signing up for a course, you agree to the 3T Software Labs Privacy Policy.


Already have an account? Log in