From the course: MongoDB Java Developer Associate Cert Prep

Unlock this course with a free trial

Join today to access over 25,500 courses taught by industry experts.

Referencing data in documents

Referencing data in documents

- Welcome. In this video, you'll learn how to model your data by using references. Before we begin, let's recap our key principle of data modeling with MongoDB. Data that is accessed together should be stored together. This means that you're storing your related data in a single document. But, there are times when you might want to store related information in separate documents, or maybe even in separate collections. When we want to store data in two different collections, but also ensure it's clear that those collections are related, we can use references. References save the _id field of one document in another document as a link between the two. References are simple and sufficient for most use cases. Using references is sometimes called linking or data normalization. Let's go through an example. This is a fairly simple document containing information about a student who has taken multiple courses. The course_id is our reference. Referencing avoids duplication of data, and, in…

Contents