Join Kirsten Hunter for an in-depth discussion in this video A brief overview of MongoDB, part of Database Clinic: MongoDB.
- [Instructor] Before we begin to address the challenges, let's talk about how MongoDB is different from other types of databases. For decades, relational databases were the gold standard for data management and processing. Enterprises and smaller companies work with SQL enabled relational databases. These databases are organized by table with each discreet type of data contained within specific tables for that data type like an address or a phone number or even invoice numbers. Keys are used to tie data between the different tables in order to construct complete data models.
Relational databases can be very complex for relatively simple schemas. For instance, a user in the system might have one or more addresses, phone numbers, or job titles. In order to retrieve information about one single entity, multiple tables need to be queried and the data tied together. This image shows the pieces necessary to show the data for just one user. Creating relational database schemas can have several disadvantages. The development and design can be complex and require the work of knowledgeable database administrators.
Changes to the schema require a change to the entire database system and a potentially expensive update operation and getting a fairly simple representation of an object in the database such as the user above requires a relatively complex database operation. Imagine how much more complicated it would be to retrieve a more detailed object. Relational databases were created with the idea of having dedicated database administrators where Mongo and other NoSql systems were designed to be accessible to programmers.
The object oriented nature of the documents better matches the way that many software engineers work with data. Gathering appropriate information can be expensive in terms of time and resources when multiple intersecting joins are needed to aggregate information. Here's an example of the call needed to find all the users named John in the system along with their related contact information. When the data is returned, it is combined into a single table with the requested information. A document database, on the other hand, keeps all of the related information contained in the same object so it's easier to access the information.
On this screen the Mongo shell is started. The first item is inserted into the users collection. Note that this collection is created dynamically when the item is inserted. After the second item is input it's a simple request to get a list of all items in the database. Here's a request for all of the documents in the system containing John as the first name. When making your request for documents in Mongo you include a document in the request describing the characteristics of the objects you want to get back. The documents themselves already contain all of the appropriate fields so no specific join operation needs to happen.
- Strengths and weaknesses of MongoDB
- Creating a database
- Joining data sets
- Combining two data collections
- Searching a database
- Creating records
- CRUD operations
- Reshaping data for calculations
- Performing calculations