One of the most common operations you’ll perform when working with MongoDB is querying document data.
The better you understand how to retrieve data, the more effectively you can access the information you need – when you need it.
Querying data is part of a larger set of operations commonly referred to as CRUD (Create, Read, Update, and Delete).
Each exercise in this section is tied to a specific CRUD operation. This will allow you to see first-hand how querying documents fits into the larger data-manipulation picture.
As part of the exercises, you’ll create a database named
sales and then add the
customers collection to the database, importing the data from a
.json file. You’ll then carry out all four MongoDB CRUD operations against the collection, using features built into Studio 3T.
Studio 3T provides a variety of tools for carrying out CRUD operations against MongoDB document data.
One of the most powerful is the Collection Tab, which includes numerous features for creating, reading, updating, and deleting data.
As soon as you open the Collection Tab, you have immediate access to the collection’s documents. You can view them in Tree View, Table View, or JSON View, and you can use the query form at the top of the Collection Tab to quickly retrieve specific documents.
You can also add, modify, and delete documents almost just as easily.
The Collection Tab is divided into two main sections.
For example, the following figure shows the customers collection tab, with the data displayed in Tree View. This is the collection you’ll be using for the exercises in this course.
You can carry out all CRUD operations within the Result tab.
If you want to change an individual value, you only need to double-click the value in the data grid and update it in-place.
If you want to make more updates, you can click the Edit Document button on the toolbar and update the JSON definition directly.
As you work through the exercises in this section, you’ll get a better sense of the many options available on the Collection Tab for performing CRUD operations. Just know that Studio 3T also provides other options for carrying out these operations, especially when it comes to querying data.
Updating and deleting data directly in a MongoDB database are irreversible operations. You should proceed cautiously whenever carrying out either type of operation. When learning how to perform CRUD operations, be sure you’re working in a test environment and not a production environment.