Lesson 1: Foundations of MongoDB / Learn

Press O for more options
4:53

Video Transcript (English)

Before we start using MongoDB to manage our data, let's take a moment to examine its foundations.

In this video, we’ll discuss what it means for MongoDB to be a distributed database. We'll also examine MongoDB's document model and flexible schema.

Like many non-relational databases, MongoDB has a distributed system architecture.

A distributed database is where the data is spread across multiple machines, or nodes. Each node may be in a different geographical location.

Because data is stored on multiple machines in a distributed database, if one machine fails, the system can still function due to this redundancy.

The distributed system architecture ensures consistent service and reliability, even when there's a system failure.

Distributed databases can also store data closer to where it's generated or accessed. This reduces latency, which enhances the user experience.

In the next video, we'll talk about MongoDB architecture so you can better understand how its distributed system works behind the scenes.

Now, let’s dive into the document model.

MongoDB stores data in JSON like documents. JSON stands for Javascript Object Notation.

JSON is a lightweight data-interchange format that is easy for humans to read and write, and easy for machines to parse and generate. Let’s look at an example document.

Notice how this document can represent an entire object or entity. Here we have just a few fields, like name, title, and interests, but we could easily add more, like an address.

All or nearly all of the information about an object or entity – whether it’s a user we’re tracking or a product in a catalog – can be contained in a single document.

And a group of documents is contained in a collection. This document is from the users collection which contains user information.

We'll dive deeper into MongoDB documents and how to model them in an upcoming unit.

The document model is unique because of its ability to handle polymorphic data and support flexible schemas. What do we mean by this?

Polymorphic data refers to data that can take on multiple forms or types within the same context or structure.

To allow for polymorphic documents, MongoDB also allows for flexible schemas.

With a flexible schema, each piece of data can have a unique structure, permitting various data types and fields within a single collection.

This is especially helpful when dealing with unstructured or semi-structured data that doesn't fit neatly into a table.

For example, let’s think about a social media app. Documents stored for this application within a posts collection will have common fields like user_id, timestamp, and likes, which are relevant for all types of posts.

And documents within this "Posts” collection will also be able to have fields that vary. A text post will have a content field for the text, a photo post will have a photo_url and caption field for the image, and a video post will have video_url, title, and duration fields.

MongoDB allows each document in the "Posts" collection to have a different structure, making it easy to store various types of content without needing multiple collections or complex data models.

This model of storing data also means that as the app evolves, new types of posts can be added easily into the schema. For instance, if the app introduces live stream posts, a new document structure can be added to the same "Posts" collection.

Given this flexibility, MongoDB is well-suited for a number of use cases. MongoDB is currently used for IoT applications, mobile apps, content management, gaming, Artificial Intelligence, and more.

MongoDB's document model is particularly beneficial for generative AI as it easily handles unstructured data and can store vector embeddings used in a variety of GenAI applications.

To help users make the most out of its document model and flexibility, MongoDB provides many processes and functions that make database management efficient and effective. We will cover these concepts in this course so you can get started using MongoDB for your applications.

Let's recap.

We've briefly discussed what it means for MongoDB to be a distributed database and examined the document model. We also discussed how MongoDB's flexible schema can handle diverse and complex data.

As we progress, you'll deepen your understanding of these concepts. So, stay tuned as we'll dive into MongoDB's architecture next.