Exercise 3: Modifying and deleting a MongoDB view

In this exercise, you’ll update the package_totals view by changing the name of the prio_support field to priority_support. After you save your changes, you’ll then delete the view.

To modify and delete the view

1. In Connection Tree, right-click the package_totals view node, and then click Edit View.

Studio 3T launches the View Editor in its own tab, as shown in the following figure.

The tab is nearly identical to the one used when creating the view, except that it now includes the Update View button, rather than Create View.

2. Go to the Stage 3 tab and, in the third line of code, replace the first instance of the string prio_support with the name priority_support, retaining the quotation marks.

This renames the output column for this stage only. The Stage 3 code should now look like the following expression:

{ 
    "package" : "$_id.package", 
    "priority_support" : "$_id.prio_support", 
    "transactions" : "$SUM(transactions)", 
    "_id" : 0
}

3. Go to the Stage 4 tab and, in the third line of code, replace the string prio_support with the word priority_support, retaining the quotation marks. This ensures that sorting is based on the correct field.

The Stage 4 code should now look like the following expression:

{ 
    "package" : 1, 
    "priority_support" : 1
}

You can, of course, make whatever changes to the pipeline stages you think necessary, as long as you ensure that the code remains viable. For now, however, these minor changes are enough to demonstrate the concept of editing a view.

4. Go to the Pipeline tab and press F5 to run the pipeline stages. This ensures that your changes will give you the expected results.

5. Click the Update View button on the View Editor toolbar. Studio 3T saves your changes to the view definition and opens the view on the package_totals view tab, which is shown in the following figure.

Update view priority

As you can see, the prio_support field name has been renamed to priority_support. Everything else remained the same.

Exercise caution when updating a view, especially if changing an output field name. You might inadvertently break an application that references the view.

6. Close the package_totals view tab, and then close the View Editor. If prompted to save changes, click Discard.

7. In the Connection Tree, right-click the package_totals view node, and then click Drop View.

8. In the Drop View dialog box, click Drop View. Studio 3T permanently removes the view from the sales databases.

9. Close Studio 3T.

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