Grokking MongoDB
0% completed
Embedding Data in Documents
A paper receipt lists every item you bought, with the quantity and the price you paid, on one sheet of paper. You do not need a second document to learn what the sale contained. An order with embedded line items works the same way: the related data is stored inside the document that uses it, and one read returns all of it.
This lesson uses one order from John Doe's shop. Insert it into the orders collection:
db.orders.insertOne({ _id: 1, customer: "John Doe", orderDate: new Date(), shippingAddress: { street: "123 Main St", city: "Anytown", zipcode: "12345" },
.....
.....
.....
Like the course? Get enrolled and start learning!
Reading Progress
0%