I'm surprised by this ability of MongoDB.
In general, I prefer SQL databases, but this ability of MongoDB is amazing.
I'm talking about nested data structures.
In a SQL database, if you want to store an order with multiple items, you usually create an order record in the orders table.
Then, you create a separate order_items table and add multiple records depending on the number of items in the order.
After that, you create relationships between them.
But MongoDB has an interesting ability to handle this differently.
Because it allows you to store related data hierarchically inside a single document.
This prevents the need for extra joins, which are required in SQL databases.
Let's understand this with an example.
Suppose you purchase 5 items. First, you create one record in the orders table, then 5 separate records in the order_items table. To retrieve the information, you need to join these tables.
But in MongoDB, you can store all the related data in one document.…