InterviewHubPRO
Section Overview
Q27

Question 27 of 60

Part 3: NoSQL & Document Databases (MongoDB, DynamoDB) (26 - 40)

45%
Databases & System Design•Part 3: NoSQL & Document Databases (MongoDB, DynamoDB) (26 - 40)

When to choose MongoDB over PostgreSQL:

In Simple Words: When schemas vary wildly between records, when data is deeply nested and accessed together, and when horizontal sharding out of the box is required.

javascript
// MongoDB polymorphic schema example (different attributes per item):
db.products.insertMany([
  { name: "Laptop", type: "electronics", cpu: "M3", ram: "16GB" },
  { name: "T-Shirt", type: "clothing", size: "L", material: "Cotton" }
]);