0
0
MongoDBquery~20 mins

Normalization vs denormalization default in MongoDB - Practice Questions

Choose your learning style9 modes available
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.