MongoDB, a powerful NoSQL database, uses flexible schema design that provides scalability, adaptability, and ease of use. Understanding its core concepts like schema design strategies, relationships (one-to-one, one-to-many, many-to-many), and scalability best practices ensures optimal database performance. This guide dives into these topics and advanced strategies from expert MongoDB chapters.
MCQs on Data Modeling in MongoDB
1. Schema Design Strategies
Which of the following is a key principle of schema design in MongoDB? a) Normalize all data b) Prioritize flexibility and performance c) Avoid indexing entirely d) Store all data in a single collection
In MongoDB, denormalization is often preferred because: a) It minimizes data redundancy b) It improves query performance c) It strictly follows relational database principles d) It simplifies schema validation
What does the “working set” refer to in schema design? a) The total database size b) Frequently accessed data c) All available indexes d) Archived data
Which MongoDB feature supports flexible schema design? a) Fixed table structures b) Dynamic schemas c) Primary key constraints d) Triggers
A schema design optimized for write-heavy workloads will: a) Use more indexes b) Reduce denormalization c) Minimize write operations d) Reduce updates by embedding data
2. Embedded vs. Referenced Documents
When should you embed documents instead of referencing? a) When data is frequently updated b) When data has a one-to-many relationship c) When data is queried together often d) When data sets are too large
Referenced documents are preferred when: a) Data is queried as a single unit b) Data changes frequently c) Data has low cardinality d) Data is hierarchical
Which of the following is NOT true about embedded documents? a) They avoid join operations b) They can grow indefinitely c) They support nested relationships d) They simplify reads
Referencing data in MongoDB is similar to: a) Using foreign keys in relational databases b) Flattening nested data structures c) Maintaining single collections d) Adding redundant data
What is the disadvantage of embedding too deeply? a) Increased write performance b) Reduced index size c) Potentially exceeding BSON document limits d) Increased query complexity
3. Relationships in MongoDB
In a one-to-one relationship, the best schema design strategy is: a) Always embedding b) Always referencing c) Embedding for tightly coupled data d) Avoiding relationships
A one-to-many relationship with frequently accessed child data should use: a) Referenced documents b) Embedded documents c) Separate collections for each child d) Flat structures
Which scenario is best suited for referencing in a many-to-many relationship? a) When relations are rarely updated b) When data needs high query performance c) When relations are sparse d) When using sharded clusters
Which collection design is recommended for storing a user’s list of addresses in MongoDB? a) Create a separate collection for addresses b) Embed addresses in the user document c) Use a single flat document for all users d) Use a hybrid of embedding and referencing
What is a common technique for handling many-to-many relationships in MongoDB? a) Embedding all related data b) Using a join collection c) Avoiding relationships altogether d) Storing data in a relational database
4. Best Practices for Scalability
What is a key consideration for scalable schema design in MongoDB? a) Minimizing data duplication b) Maximizing embedding c) Avoiding indexes d) Optimizing sharding
Why is it important to limit document size in MongoDB? a) To maximize BSON limits b) To reduce memory consumption c) To prevent index fragmentation d) To improve backup times
Sharding in MongoDB helps to: a) Combine collections into a single unit b) Distribute data across multiple servers c) Avoid schema validation d) Improve single-server performance
What is the recommended approach for write-heavy workloads? a) Normalize data b) Use sharding with hashed keys c) Reduce indexes d) Use a secondary index for writes
MongoDB indexes should be used: a) For every field b) Sparingly on queried fields c) Only on embedded documents d) Without considering storage
5. Expert Section (Chapters 6–10)
What is the maximum size of a BSON document in MongoDB? a) 8 MB b) 16 MB c) 32 MB d) 64 MB
The Aggregation Framework is best for: a) Complex queries and transformations b) CRUD operations c) Defining relationships d) Index management
What is a pipeline stage in MongoDB Aggregation? a) A single operation in the query plan b) A step in a data transformation process c) A method for defining indexes d) A schema validation tool
Which command is used to create a text index in MongoDB? a) createIndex({ field: “text” }) b) db.createIndex({ field: 1 }) c) db.createIndex({ field: “hashed” }) d) addIndex({ field: “text” })
Which of these is NOT a benefit of the Aggregation Framework? a) Real-time data processing b) Efficient data transformation c) Advanced analytics d) Schema validation
Which sharding strategy minimizes query routing overhead? a) Hashed shard keys b) Range-based shard keys c) Random shard keys d) Sequential shard keys
In MongoDB, capped collections are: a) Fixed-size collections optimized for high throughput b) Unlimited collections for large data sets c) Auto-sharded collections d) Collections with nested documents
Which MongoDB operator is used for array aggregation? a) $concat b) $unwind c) $mergeObjects d) $lookup
Time-to-Live (TTL) indexes are used for: a) Controlling query performance b) Automatically deleting expired documents c) Managing transactions d) Implementing full-text search
What is the purpose of the $graphLookup operator? a) Text search optimization b) Recursive queries in hierarchical data c) Aggregating flat documents d) Managing indexes
Answer Key
QNo
Answer (Option with Text)
1
b) Prioritize flexibility and performance
2
b) It improves query performance
3
b) Frequently accessed data
4
b) Dynamic schemas
5
d) Reduce updates by embedding data
6
c) When data is queried together often
7
b) Data changes frequently
8
b) They can grow indefinitely
9
a) Using foreign keys in relational databases
10
c) Potentially exceeding BSON document limits
11
c) Embedding for tightly coupled data
12
b) Embedded documents
13
c) When relations are sparse
14
b) Embed addresses in the user document
15
b) Using a join collection
16
d) Optimizing sharding
17
b) To reduce memory consumption
18
b) Distribute data across multiple servers
19
b) Use sharding with hashed keys
20
b) Sparingly on queried fields
21
b) 16 MB
22
a) Complex queries and transformations
23
b) A step in a data transformation process
24
a) createIndex({ field: “text” })
25
d) Schema validation
26
b) Range-based shard keys
27
a) Fixed-size collections optimized for high throughput