Exercise 4: Updating data directly within the collection

In this exercise, you will update the documents returned by the query you ran in the previous exercise. You will update two individual values, update the data type for one of the fields, and bulk update the value in another field.

To update the data

1. On the welsh_pubs collection tab, ensure that the collection data is displayed in Table View.

2. On the Result tab, double-click the SNOOKER WORLD value in the name field to enter editing mode.

Visual snooker world

Change the value to Snooker World (from all capital letters to title caps).

Letter edited

When you enter editing mode, an ellipsis button appears. Clicking the button opens a text box for working with longer field values.

3. Repeat Step 2 for the value TERRY GRIFFITHS SNOOKER CLUB, changing it to Terry Griffiths Snooker Club.

4. On the Result tab, right-click one of the values in the fsa_id field, point to Field, and then click Edit Value / Type.

Edit value tab

5. In the Edit Value dialog box, select Int64 from the Type drop-down list.

6. From the Set this field in drop-down list, select Documents matching query criteria.

7. Select the Only change type (“Convert”) option and type 0 in the Fallback Value text box.

Edit value

Use caution when bulk updating data types or values, or you could inadvertently modify all documents in the collection.

8. Click Set Value.

A message box should appear, confirming that all 14 documents were updated.

Edit value update

9. Click OK to close the message box.

The fsa_id column should now indicate the Int64 data type.

10. Right-click one of the values in the local_authority field, point to Field, and then click Edit Value / Type.

Local authority edit value

11. From the Set this field in drop-down list, select Documents matching query criteria.

12. Ensure that the Always change value (“Force”) option is selected and then type Wales Snooker in the Value text box.

wales updated

13. Click Set Value.

A message box should appear, confirming that all 14 documents were updated.

14. Click OK to close the message box.

Your documents should now look like those in the following figure. 

wales result tab

15. In the Connection Tree, right-click the pubs database node and click Drop Database.

16. In the Drop Database dialog box, click Drop Database.

Dropping a database removes the current database, deleting the associated data files.

17. 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