Learn the differences between document databases and traditional databases. Also, get introduced to Mongo.
- [Instructor] Let's go through a quick overview on MongoDB. If you're familiar with relational database systems you may be used to thinking of data in terms of rows and columns with distinct tables containing very particular types of information. This kind of setup is excellent for data which is tabular in nature. Things where a spreadsheet might be a good match. Think of reporting, billing, invoices and other places where the relationship between data is critically important and fields must be consistent across all members of a data type.
One way to understand the reason for a document database is to look at site like Craigslist. If you're not familiar with Craigslist, it's a huge classified list with services, items and jobs. The number of postings is enormous and they keep every posting that's ever been made. Older post may not have had things like tags or images, but newer items can be more detailed. When using MySQL, Craigslist updated the archive tables every three months to keep them in sync with the live database. Unfortunately at one point, they realized that the altered table command was going to take more than three months to run.
And so they'd never catch up. Since they were not gaining any advantages by using a relational database, they looked elsewhere for a data store which would better suit their needs. Where relational database stores items in distinct tables with very specific data types and ties them together using keys, a document database stores items in collections. A collection can have documents which are shaped the same way with the same schema. But a collection can also have documents which have different fields or even different types of the information in a single field.
This flexibility allows developers to design schemas that make sense for their use case and removes the requirement to update the entire database schema whenever a change needs to be made. Additionally, a document database can represent nested information where appropriate. To understand this sort of thing, imagine a system which has Wiki and Blog functionality. You could have a collection called Pages and store both Wiki and blog posts in there. You could have tags, used for either type of page.
Also there could be an author object within each of these pages and you could use that information for sorts and searches. Another example to consider is a movie catalog. You may have movies but those movies also have casts and directors along with many related pieces of data. How handy is it to be able to run searches across the various people types and group the results to determine which movies are associated with a particular individual. Contrast this with the much stricter world of relational databases where any type of data aggregation requires expensive join commands.
Expensive both in terms of computing resources, but also in terms of actual elapsed time. When you use Mongo, you have the ability to index your data however it makes sense to you. Allowing you to find pages both in the Wiki and blog, belonging to a particular author or finding a movie with a particular tag without waiting for a long operation to complete. When we take a look at the indexing functionality, you'll see how much more quickly searches can be run. And how these features work together to create a powerful data store.
It's also important to remember the advantages of having an editable schema. What if you decided to add a related pages section to the newer pages in your database? Would it make sense to have to change the entire structure of the database just to process new pages with this additional field? Adding new fields and functionality is one of the things made significantly easier with a document database like MongoDB. Mongo features drivers for most modern programming languages. And these drivers are owned and maintained by a company called 10gen.
These drivers behave consistently across languages, while still using idiomatically correct language syntax for each programming environment. In this course, we'll be working with the node MongoDB driver known as Mongoose. But if you want to work with another language, you should definitely seek out the correct driver.
- Setting up the development environment
- Consuming an API using HTTPie
- Inspecting Mongo data
- Updating the server for MongoDB read functionality
- Setting up application endpoints
- Implementing user endpoints, progress endpoints, and promises