Bird
Raised Fist0
MongoDBquery~20 mins

Normalization vs denormalization default in MongoDB - Practice Questions

Choose your learning style10 modes available

Start learning this pattern below

Jump into concepts and practice - no test required

or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Challenge - 5 Problems
🎖️
Normalization vs Denormalization Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
Understanding Default Data Organization in MongoDB
In MongoDB, when you design your data model without explicitly embedding related data, what is the default approach to organizing data?
AData is normalized by storing references between documents
BData is denormalized by embedding all related data in one document
CData is stored in flat tables like in relational databases
DData is automatically partitioned across multiple collections
Attempts:
2 left
💡 Hint
Think about how MongoDB stores documents by default when you don't embed related data.
query_result
intermediate
2:00remaining
Query Result with Normalized Data References
Given two collections in MongoDB: users and orders. Each order document stores a userId referencing a user. What will be the output of this aggregation query that looks up user info for each order?
MongoDB
db.orders.aggregate([
  { $lookup: {
      from: 'users',
      localField: 'userId',
      foreignField: '_id',
      as: 'userInfo'
  }},
  { $unwind: '$userInfo' },
  { $project: { _id: 0, orderId: 1, 'userInfo.name': 1 } }
])
A[{ orderId: 101, userId: 'Alice' }, { orderId: 102, userId: 'Bob' }]
B[{ orderId: 101, userInfo: 'Alice' }, { orderId: 102, userInfo: 'Bob' }]
C[{ orderId: 101, userInfo: { name: 'Alice' } }, { orderId: 102, userInfo: { name: 'Bob' } }]
D[]
Attempts:
2 left
💡 Hint
Look at how $lookup and $unwind work to join and flatten the user info.
📝 Syntax
advanced
2:00remaining
Identify the Syntax Error in Denormalized Document Update
Which of the following MongoDB update commands correctly updates the embedded address city in a denormalized user document?
MongoDB
User document example: { _id: 1, name: 'John', address: { city: 'Oldtown', zip: '12345' } }
Adb.users.updateOne({ _id: 1 }, { $set: { address.city: 'Newtown' } })
Bdb.users.updateOne({ _id: 1 }, { $set: { 'address.city': 'Newtown' } })
Cdb.users.updateOne({ _id: 1 }, { $set: { 'address->city': 'Newtown' } })
Ddb.users.updateOne({ _id: 1 }, { $set: { address['city']: 'Newtown' } })
Attempts:
2 left
💡 Hint
Check the correct way to specify nested fields in MongoDB update operators.
optimization
advanced
2:00remaining
Optimizing Read Performance with Denormalization
You have a MongoDB collection where user profiles embed their recent activity logs. Which of the following is a key advantage of this denormalized design compared to normalized references?
AFaster reads because all related data is in one document, reducing the need for joins
BSmaller document size leading to less storage usage
CEasier to maintain consistency across multiple collections
DAutomatic indexing of embedded documents without extra configuration
Attempts:
2 left
💡 Hint
Think about how embedding affects the number of queries needed to get related data.
🔧 Debug
expert
3:00remaining
Debugging Data Inconsistency in Mixed Normalization Design
A MongoDB application stores user data with some fields embedded (denormalized) and others referenced (normalized). After updating a user's email in the users collection, the embedded email in orders documents is not updated. What is the most likely cause?
AThe orders collection is read-only and cannot be updated
BMongoDB automatically updates embedded fields but the update query is incorrect
CThe email field cannot be embedded and referenced at the same time by design
DThe application does not update embedded email fields in orders after changing the user email
Attempts:
2 left
💡 Hint
Consider how denormalized data requires manual synchronization.

Practice

(1/5)
1. What is the main advantage of normalization in MongoDB databases?
easy
A. It separates data into collections linked by references for easy updates.
B. It stores all related data together in one document for faster reads.
C. It duplicates data to improve write performance.
D. It automatically creates indexes on all fields.

Solution

  1. Step 1: Understand normalization concept

    Normalization means splitting data into separate collections and linking them by references.
  2. Step 2: Identify the main benefit

    This separation makes updating data easier because changes happen in one place without duplication.
  3. Final Answer:

    It separates data into collections linked by references for easy updates. -> Option A
  4. Quick Check:

    Normalization = separate collections + easy updates [OK]
Hint: Normalization means separate collections linked by references [OK]
Common Mistakes:
  • Confusing normalization with denormalization
  • Thinking normalization duplicates data
  • Assuming normalization speeds up reads
2. Which MongoDB document structure shows denormalization?
easy
A. { _id: 1, name: 'Alice' }, { _id: 101, userId: 1, item: 'Book' }
B. { _id: 1, name: 'Alice', orders: [ { orderId: 101, item: 'Book' } ] }
C. { _id: 101, userId: 1, item: 'Book' }
D. { _id: 1, name: 'Alice', orders: null }

Solution

  1. Step 1: Identify denormalized structure

    Denormalization stores related data together inside one document, like embedding orders inside user.
  2. Step 2: Check options for embedded data

    { _id: 1, name: 'Alice', orders: [ { orderId: 101, item: 'Book' } ] } embeds orders array inside the user document, showing denormalization.
  3. Final Answer:

    { _id: 1, name: 'Alice', orders: [ { orderId: 101, item: 'Book' } ] } -> Option B
  4. Quick Check:

    Denormalization = embedded related data [OK]
Hint: Denormalization embeds related data inside one document [OK]
Common Mistakes:
  • Choosing separate collections as denormalized
  • Ignoring embedded arrays as denormalization
  • Confusing null fields with embedded data
3. Given these two collections:
users: { _id: 1, name: 'Bob' }
orders: { _id: 101, userId: 1, item: 'Pen' }
What is the main drawback of this normalized design when reading user orders?
medium
A. It requires multiple queries or a join-like operation to get all orders for a user.
B. It duplicates order data inside each user document.
C. It stores all orders inside the user document causing large documents.
D. It prevents updating user names easily.

Solution

  1. Step 1: Understand normalized design

    Users and orders are in separate collections linked by userId reference.
  2. Step 2: Identify drawback when reading

    To get all orders for a user, you must query orders collection filtering by userId, requiring multiple queries or aggregation.
  3. Final Answer:

    It requires multiple queries or a join-like operation to get all orders for a user. -> Option A
  4. Quick Check:

    Normalized read = multiple queries [OK]
Hint: Normalized data needs multiple queries to combine related info [OK]
Common Mistakes:
  • Thinking normalized data duplicates info
  • Assuming all data is embedded in one document
  • Believing updates are harder in normalized data
4. You have a denormalized MongoDB document:
{ _id: 1, name: 'Carol', orders: [ { orderId: 201, item: 'Notebook' } ] }
Which problem can occur if you update the item name in one order but forget to update it elsewhere?
medium
A. Query performance slows down because of references.
B. Indexes on orders array are lost.
C. The database schema becomes normalized automatically.
D. Data inconsistency due to duplicated order info in multiple documents.

Solution

  1. Step 1: Recognize denormalization risk

    Denormalization duplicates related data inside documents, so the same order info may appear in many places.
  2. Step 2: Understand update problem

    If you update one copy but not others, data becomes inconsistent and unreliable.
  3. Final Answer:

    Data inconsistency due to duplicated order info in multiple documents. -> Option D
  4. Quick Check:

    Denormalization risk = data inconsistency [OK]
Hint: Denormalization can cause inconsistent duplicated data if not updated everywhere [OK]
Common Mistakes:
  • Thinking denormalization slows queries
  • Believing schema changes automatically
  • Confusing index loss with denormalization
5. You want to design a MongoDB schema for a blog with users and posts.
Users have many posts, and posts rarely change after creation.
Which design is best for fast reading and why?

Options:
A: Store users and posts in separate collections (normalized).
B: Embed all posts inside each user document (denormalized).
C: Duplicate posts in both users and posts collections.
D: Store posts only, with user info duplicated in each post.
hard
A. Separate collections for users and posts for easy updates.
B. Store posts only with duplicated user info for simpler queries.
C. Embed posts inside user documents for fast reads since posts rarely change.
D. Duplicate posts in both collections to optimize writes.

Solution

  1. Step 1: Analyze data change frequency

    Posts rarely change, so embedding them inside users won't cause frequent update problems.
  2. Step 2: Choose design for fast reads

    Embedding posts inside user documents allows fetching user and posts in one read, improving read speed.
  3. Step 3: Compare options

    Embedding posts inside user documents for fast reads since posts rarely change fits best for fast reads with rare updates; separate collections require joins; duplicating posts in both risks inconsistency; storing posts only duplicates user info unnecessarily.
  4. Final Answer:

    Embed posts inside user documents for fast reads since posts rarely change. -> Option C
  5. Quick Check:

    Denormalization + rare updates = embed for fast reads [OK]
Hint: Embed rarely changing related data for faster reads [OK]
Common Mistakes:
  • Choosing normalization for fast reads
  • Duplicating data causing inconsistency
  • Ignoring update frequency in design