Exercise 1: Using IntelliShell to load and run a script file

In this exercise, you will load and run the bios.js file.

Download the bios.js file here.

The file contains a set of commands that create a database named BioData and add a collection to the database named bios. The collection includes 10 documents that contain biographical information about 10 individuals, one document per individual.

The document data comes from a sample collection available through the MongoDB Server manual. You can use this dataset to learn about MongoDB and test its features.

To load and run the script file

1. Launch Studio 3T and connect to MongoDB.

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

3. In the Add Database dialog box, type BioData in the Database Name text box, and then click OK.

add biodata

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

4. In the Connection Tree, right-click on the database (BioData) and click Open IntelliShell.

open intellishell

3. If you haven’t already done so, download the bios.js file and save it to a local folder on your system.

4. On the IntelliShell toolbar, click on the lightning bolt icon (Auto-completion icon) to trigger auto-completion. IntelliShell will then auto-suggest hints as you type.

Then, de-select the Retain previous result tabs button if selected.

previous result tab

Also, select the Raw shell mode button if not selected.

Raw shell mode

This ensures that, for this exercise, the results are displayed on a single result tab.

5. In the IntelliShell editor, delete any existing commands and type the following command, replacing the <path> placeholder with the actual folder path:

load("<path>bios.js");

Backslashes can be interpreted in different ways, often indicated by an escape character.  When specifying the path, you might need to escape any backslashes by adding an additional backslash to each one.

For example, if you’re working in Windows and save the bios.js file to the folder C:\DataFiles\MongoDB, you would type the following command in the IntelliShell editor:

load("C:\\DataFiles\\MongoDB\\bios.js");

macOS, on the other hand, uses forward slashes. If saving to the same folder, you would type the following command:

load("/DataFiles/MongoDB/bios.js");

The load method loads and runs a script file, which in this case is bios.js.

6. Click the Execute entire script button (Execute entire script). You should receive a message that says true.

Execute script

7. In the Connection Tree, right-click the connection (top-level node) and click Refresh All.

This creates the bios collection.

8. Expand the BioData database node, and then expand the Collections node if necessary.

Double-click the bios collection node to open the collection in its own tab.

9. Go to the bios collection tab and review the 10 documents, using Tree View, Table View, or JSON View.

Tree view

The documents include the following fields:

  • The _id field is a unique Int32 value that identifies the document.
  • The name field is an embedded document that provides the individual’s first and last name, along with other names, if applicable.
  • The birth field is a Date value that indicates when the individual was born.
  • The death field is a Date value that indicates when the individual died.
  • The contribs field is an array that lists the individual’s contributions to technology.
  • The awards field is as an array in which each element is an embedded document that includes specific award information.
  • The title field is a String value that lists the individual’s title. Not all documents contain every field; however, each document includes at least the _idname, and contribs fields. Leave the bios collection tab open for now in case you want to reference the documents in later exercises to see how they’re constructed.

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