MongoDB MongoDB Data Modeling 1 — Questions and Answers
Question 1: What is the embedded document (denormalized) data model in MongoDB?
- Storing related data as separate referenced documents
- Storing related data as nested subdocuments within a single document (Correct answer)
- Embedding JavaScript functions in documents
- Using base64 encoding for binary data
Correct answer: Storing related data as nested subdocuments within a single document
Embedding stores related data in a single document as nested subdocuments, improving read performance by avoiding joins but potentially increasing document size.
Question 2: When should you prefer the reference (normalized) data model over embedding?
- When documents are always queried together
- When data is rarely accessed
- When data is frequently accessed independently or shared across multiple documents (Correct answer)
- When documents are small and simple
Correct answer: When data is frequently accessed independently or shared across multiple documents
References (storing related document _ids) are preferred when related data is large, changes frequently, or is shared by multiple parent documents.
Question 3: What is MongoDB's document size limit?
- 1 MB
- 4 MB
- 16 MB (Correct answer)
- 64 MB
Correct answer: 16 MB
MongoDB limits individual documents to 16 MB, which prevents excessive memory usage and encourages proper data modeling.
Question 4: What is the 'bucket pattern' in MongoDB data modeling?
- Distributing documents across multiple collections
- Grouping time-series data into documents covering a time range (Correct answer)
- Storing binary data in chunks
- Creating separate collections per user
Correct answer: Grouping time-series data into documents covering a time range
The bucket pattern groups related time-series data into documents that each cover a defined time period, reducing the number of documents and improving query performance.
Question 5: What is the 'outlier pattern' in MongoDB data modeling used for?
- Handling documents with unusually large field counts
- Handling documents whose arrays would exceed the size limit by using overflow documents (Correct answer)
- Filtering statistical outliers in queries
- Handling rare edge cases in schema validation
Correct answer: Handling documents whose arrays would exceed the size limit by using overflow documents
The outlier pattern handles edge cases where most documents have small arrays but a few have very large ones by storing overflow data in additional linked documents.
Question 6: Which of the following best describes a polymorphic schema in MongoDB?
- A schema that changes automatically over time
- A collection storing documents with varying but related structures (Correct answer)
- A schema generated from multiple programming languages
- A schema that inherits from a parent schema
Correct answer: A collection storing documents with varying but related structures
Polymorphic schema allows different documents in the same collection to have different fields while still representing related entities.
What is the embedded document (denormalized) data model in MongoDB?