0
0
MongoDBquery~20 mins

Embedding vs referencing decision in MongoDB - Practice Questions

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
MongoDB Embedding vs Referencing Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
When to use embedding in MongoDB?
Which scenario is best suited for embedding documents in MongoDB?
AWhen data needs to be shared across multiple collections
BWhen related data is very large and updated independently
CWhen related data is frequently accessed together and has a one-to-few relationship
DWhen data size exceeds MongoDB document size limit
Attempts:
2 left
💡 Hint
Think about data that is tightly connected and often retrieved in one go.
🧠 Conceptual
intermediate
2:00remaining
When to use referencing in MongoDB?
Which situation calls for referencing documents instead of embedding in MongoDB?
AWhen related data is large or shared among many documents
BWhen related data is small and rarely updated
CWhen data is always accessed together
DWhen data fits comfortably within a single document
Attempts:
2 left
💡 Hint
Consider data that is reused or updated separately.
query_result
advanced
3:00remaining
Output of embedding vs referencing query
Given two collections, users with embedded addresses and orders referencing users, what is the output of this query?
MongoDB
db.orders.aggregate([
  { $lookup: {
      from: 'users',
      localField: 'user_id',
      foreignField: '_id',
      as: 'user_info'
  }},
  { $unwind: '$user_info' },
  { $project: {
      order_id: 1,
      'user_info.name': 1,
      'user_info.address.city': 1
  }}
])
A[]
B[{ order_id: 101, user_info: { name: 'Alice', address: { city: 'Seattle' } } }, { order_id: 102, user_info: { name: 'Bob', address: { city: 'Austin' } } }]
C[{ order_id: 101, user_info: { address: { city: 'Seattle' } } }, { order_id: 102, user_info: { address: { city: 'Austin' } } }]
D[{ order_id: 101, user_info: { name: 'Alice' } }, { order_id: 102, user_info: { name: 'Bob' } }]
Attempts:
2 left
💡 Hint
Look at the $project stage selecting name and address.city fields.
schema
advanced
3:00remaining
Choose the best schema design for a blog with comments
You are designing a MongoDB schema for a blog where each post can have hundreds of comments. Which design is best?
AStore comments in a separate collection referencing the post
BEmbed only the first 10 comments inside the post, rest in a separate collection
CEmbed all comments inside the post document
DStore comments as an array of comment IDs inside the post document
Attempts:
2 left
💡 Hint
Consider document size limits and update frequency.
optimization
expert
4:00remaining
Optimizing queries with embedding vs referencing
You have a MongoDB collection of products and a collection of reviews referencing products. You want to optimize read performance for showing product details with reviews. Which approach is best?
AStore review IDs inside product and fetch reviews separately in application code
BKeep reviews in a separate collection and use $lookup to join at query time
CEmbed all reviews inside each product document
DEmbed only the latest 3 reviews inside product, keep others separate
Attempts:
2 left
💡 Hint
Balance document size and query speed for common use cases.