Document Database 00:00:01 Pack the order the way someone opens it A bakery sends a delivery driver one order containing an address and three pastries. A document database can keep those related values inside one record, preserving the shape the driver actually needs to read. The application sends a JSON-like object with a name and an email. The collection has a rule: email is required. The document passes. A document without it would be rejected. The document is stored as one piece, with its nested fields. With majority write concern the acknowledgment waits for the required majority of voting, data-bearing replica-set members. Flexible fields still need a contract. A validation rule can reject a missing email, while an old document can retain its earlier shape until the application migrates or handles it. 00:00:52 Find one customer by email Now a support worker has an email address rather than a document identifier. An index provides a second entrance to the records. A projection selects the fields that may come back to the worker. The filter asks for one email. The options ask for name and email only. The index is sorted by email, so a few steps lead to the matching document. The document is read from storage, or from memory if it is already there. Results stream back in batches. Here there is one result. The index costs space and maintenance on writes. Choose it for a recurring lookup and inspect the query plan. Returning only a name and email also avoids exposing the delivery note. 00:01:38 Change a field without replacing the order Two drivers sign in at the same time. Downloading the whole document, changing a number and putting it back can lose an increment. The database offers an update that performs the arithmetic on the server. Find the customer by email, then request three changes together. Set the status, increment the login count and append a role. $set replaces one field and leaves the others alone. $inc adds on the server, so two logins at once count twice. $push adds to the list. The new version replaces the old one in one atomic step. Only indexes on changed fields move: a status index would, the email index does not. Test the boundary carefully. Several changes inside one document can share one atomic update. A business rule spanning two independent documents needs a different arrangement or a multi-document transaction. 00:02:34 Which facts travel together? An order's purchased pastries belong to that order. The baker's current contact number belongs to the baker and can appear on thousands of orders. Those relationships call for different shapes. A handful, always shown with the order, belong to nobody else: embed. They can grow without end, so the other questions do not matter: reference. Shared by several pets and it changes. Every copy would need an update: reference. Shared, shown together and nearly never changes. A small copy saves a query each time. An order may intentionally retain a historical delivery address. An on-call phone number needs one current source. Decide which meaning a copy represents before deciding where the copy should live. 00:03:19 The box that never stops growing Imagine embedding every comment beneath a popular bakery post. The first page looks beautifully simple when it has ten comments. By the time a city discovers it, one small read drags an enormous history along. Ten comments inside the post. One read shows the page. 10,000 comments are 2 MB. The page shows ten but the document carries them all. At this example's average comment size the document eventually approaches MongoDB's sixteen mebibyte document limit. A count alone cannot predict the exact boundary. The post keeps the latest 10 and a count. All comments live in their own collection. Keep a bounded preview on the post and page through a separate collection for the history. The durable design rule is to embed related, bounded data and give growing or independently changing records their own identity.