Projection with dot notation = filtered subfields [OK]
Hint: Use dot notation in projection to include subfields only [OK]
Common Mistakes:
Expecting full subdocuments when projecting subfields
Forgetting _id is included by default
Assuming projection excludes _id without explicit exclusion
4. You designed a schema embedding user addresses inside user documents, but queries on addresses are slow. What is the likely problem?
medium
A. MongoDB does not support embedding arrays
B. Embedding always makes queries slower
C. You must store addresses in a separate database
D. Addresses should be referenced separately if they are large or updated often
Solution
Step 1: Identify embedding drawbacks
Embedding large or frequently changing data can cause large documents and slow updates or queries.
Step 2: Choose referencing for large or mutable data
Referencing addresses separately keeps user documents small and improves query speed on addresses.
Final Answer:
Addresses should be referenced separately if they are large or updated often -> Option D
Quick Check:
Large mutable data = use referencing [OK]
Hint: Reference large or changing data to keep documents small [OK]
Common Mistakes:
Assuming embedding always improves speed
Thinking MongoDB disallows embedding arrays
Believing separate databases are needed for performance
5. You have a read-heavy app showing user profiles with many posts. Posts change often, but profiles rarely do. How should you design the schema for fast reads?
hard
A. Embed user profile data inside each post document
B. Embed posts inside user profiles despite frequent changes
C. Store user profiles and posts in separate collections, referencing posts from profiles
D. Duplicate posts data inside profiles and update both on changes
Solution
Step 1: Analyze data change frequency
Posts change often; embedding them inside profiles would cause large documents and frequent updates.
Step 2: Choose referencing for frequently changing large data
Storing posts separately and referencing them keeps profiles small and reads fast.
Step 3: Avoid data duplication to prevent sync issues
Duplicating posts in profiles causes update complexity and inconsistency risks.
Final Answer:
Store user profiles and posts in separate collections, referencing posts from profiles -> Option C
Quick Check:
Frequent changes = referencing large data [OK]
Hint: Reference frequently changing data, embed stable data [OK]