C.Documents in a collection can have different fields
D.Collections can contain only identical documents
Correct Answer: Documents in a collection can have different fields
Explanation:
MongoDB allows documents in the same collection to have different fields and structures.
Incorrect! Try again.
2Which data format does MongoDB use to store documents internally?
Schema-less Nature of MongoDB
Easy
A.XML
B.CSV
C.YAML
D.BSON
Correct Answer: BSON
Explanation:
MongoDB stores documents internally in BSON, a binary representation of JSON-like data.
Incorrect! Try again.
3In MongoDB, what is a collection?
Schema-less Nature of MongoDB
Easy
A.A group of related documents
B.A single field in a document
C.A link between two servers
D.A rule for sorting values
Correct Answer: A group of related documents
Explanation:
A collection groups related MongoDB documents, much like a table groups rows in a relational database.
Incorrect! Try again.
4What does embedding mean in MongoDB data modeling?
Embedding vs. Referencing
Easy
A.Storing related data inside one document
B.Storing related data on another server
C.Deleting repeated fields from documents
D.Creating separate databases for each field
Correct Answer: Storing related data inside one document
Explanation:
Embedding places related data in a nested document or array within the parent document.
Incorrect! Try again.
5What does referencing mean in MongoDB?
Embedding vs. Referencing
Easy
A.Converting document fields into indexes
B.Combining every collection into one document
C.Copying all data into each collection
D.Connecting documents by storing an identifier
Correct Answer: Connecting documents by storing an identifier
Explanation:
Referencing links separate documents by storing an identifier, usually the _id of another document.
Incorrect! Try again.
6When is embedding commonly preferred?
Embedding vs. Referencing
Easy
A.When documents belong to separate databases
B.When the nested array grows without limit
C.When related data is usually read together
D.When related data changes independently
Correct Answer: When related data is usually read together
Explanation:
Embedding is useful when related data is commonly accessed as a single unit.
Incorrect! Try again.
7Which example represents a one-to-one relationship?
One-to-One Relationships
Easy
A.One teacher and many students
B.Many authors and many books
C.One employee and one ID card
D.One store and many products
Correct Answer: One employee and one ID card
Explanation:
A one-to-one relationship connects one record with exactly one corresponding record.
Incorrect! Try again.
8How can a one-to-one relationship be modeled when both records are commonly accessed together?
One-to-One Relationships
Easy
A.Embed one record in the other
B.Store each record in a database
C.Duplicate both records repeatedly
D.Place each field in a collection
Correct Answer: Embed one record in the other
Explanation:
Embedding is a simple choice when both sides of a one-to-one relationship are usually retrieved together.
Incorrect! Try again.
9Which example represents a one-to-many relationship?
One-to-Many Relationships
Easy
A.One product and one serial number
B.One citizen and one passport
C.Many students and many courses
D.One customer and many orders
Correct Answer: One customer and many orders
Explanation:
A customer can place multiple orders, while each order can belong to one customer.
Incorrect! Try again.
10How can a small, bounded one-to-many relationship be stored in MongoDB?
One-to-Many Relationships
Easy
A.Remove the relationship identifiers
B.Embed the many items in an array
C.Create one database per item
D.Store every value as plain text
Correct Answer: Embed the many items in an array
Explanation:
A small and limited set of related items can be embedded as an array in the parent document.
Incorrect! Try again.
11When is referencing often preferred for a one-to-many relationship?
One-to-Many Relationships
Easy
A.When all values fit in a single nested object
B.When the number of related items can grow greatly
C.When the related data always remains very small
D.When the relationship has exactly one item
Correct Answer: When the number of related items can grow greatly
Explanation:
Referencing helps prevent a parent document from growing too large when it has many related items.
Incorrect! Try again.
12Which example represents a many-to-many relationship?
Many-to-Many Relationships
Easy
A.One city and many streets
B.One author and many drafts
C.One user and one profile
D.Many students and many courses
Correct Answer: Many students and many courses
Explanation:
A student can join many courses, and each course can include many students.
Incorrect! Try again.
13What is a common way to model a many-to-many relationship in MongoDB?
Many-to-Many Relationships
Easy
A.Remove identifiers from related documents
B.Store arrays of related document identifiers
C.Store all records in one text field
D.Create one server for each relationship
Correct Answer: Store arrays of related document identifiers
Explanation:
Arrays of identifiers can reference multiple related documents on either side of the relationship.
Incorrect! Try again.
14What should primarily guide a MongoDB data model?
Data Modeling Best Practices
Easy
A.The number of database users
B.The alphabetical order of fields
C.The application's data access patterns
D.The length of collection names
Correct Answer: The application's data access patterns
Explanation:
MongoDB schemas should be designed around how the application reads, writes, and updates data.
Incorrect! Try again.
15Why should unbounded arrays generally be avoided?
Data Modeling Best Practices
Easy
A.They prevent documents from having identifiers
B.They allow only numeric field values
C.They can make documents grow excessively
D.They automatically delete older documents
Correct Answer: They can make documents grow excessively
Explanation:
An array that grows without a limit can make its document too large and inefficient to manage.
Incorrect! Try again.
16What is denormalization in MongoDB data modeling?
Data Modeling Best Practices
Easy
A.Splitting each document into databases
B.Encrypting every field before storage
C.Removing all indexes from collections
D.Duplicating selected data to improve reads
Correct Answer: Duplicating selected data to improve reads
Explanation:
Denormalization stores selected data in more than one place to reduce lookups and improve read performance.
Incorrect! Try again.
17In a blog application, where can a small number of comments be stored when they are always shown with a post?
Case Studies and Examples
Easy
A.Inside the user password field
B.Inside the database settings
C.Inside the post document
D.Inside the collection name
Correct Answer: Inside the post document
Explanation:
Embedding comments in the post is suitable when the comment list is small and normally retrieved with the post.
Incorrect! Try again.
18In an online store, why might products be referenced from orders instead of fully embedded?
Case Studies and Examples
Easy
A.Products cannot contain text fields
B.Orders cannot store nested documents
C.Products may be shared across many orders
D.Collections cannot store product names
Correct Answer: Products may be shared across many orders
Explanation:
Referencing is useful when the same product can be related to many different orders.
Incorrect! Try again.
19What is the purpose of schema validation in MongoDB?
Validation Rules and Constraints
Easy
A.To enforce rules on document structure
B.To sort all documents by _id
C.To rename collections automatically
D.To create backups after every query
Correct Answer: To enforce rules on document structure
Explanation:
Schema validation checks that inserted or updated documents follow defined structural and data-type rules.
Incorrect! Try again.
20Which MongoDB feature can define validation rules for fields?
Validation Rules and Constraints
Easy
A.HTML Form
B.CSV Header
C.JSON Schema
D.DNS Record
Correct Answer: JSON Schema
Explanation:
MongoDB supports JSON Schema validation for requirements such as field types and required properties.
Incorrect! Try again.
21A MongoDB collection stores products from several categories. Books have an author field, while laptops have a processor field. What does MongoDB's schema-less nature allow in this situation?
Schema-less Nature of MongoDB
Medium
A.Fields are automatically moved into separate collections
B.Documents may contain different fields in the same collection
C.Every document must contain both category-specific fields
D.Field differences are allowed only for unindexed data
Correct Answer: Documents may contain different fields in the same collection
Explanation:
MongoDB allows documents in one collection to have different structures, making it suitable for heterogeneous product data.
Incorrect! Try again.
22An application stores price as a number in some documents and as a string in others. A range query produces unreliable results. What is the best design response?
Schema-less Nature of MongoDB
Medium
A.Move each price type to a separate database
B.Store price consistently as a numeric type
C.Remove the price field from all indexes
D.Convert every numeric price into an array
Correct Answer: Store price consistently as a numeric type
Explanation:
A schema-less database still benefits from consistent field types, especially when fields are queried, sorted, or indexed.
Incorrect! Try again.
23A user profile has one shipping address that is small, displayed with the profile, and rarely updated separately. Which model is most suitable?
Embedding vs. Referencing
Medium
A.Reference the address from a separate collection
B.Embed the address inside the user document
C.Store the user inside the address document
D.Duplicate the address across multiple databases
Correct Answer: Embed the address inside the user document
Explanation:
Embedding is appropriate when related data is small, bounded, and usually retrieved with its parent.
Incorrect! Try again.
24Thousands of orders may refer to the same customer, and customer contact details change regularly. Which approach best avoids widespread duplicate updates?
Embedding vs. Referencing
Medium
A.Embed the complete customer in each order
B.Store all orders inside the customer name field
C.Create a new customer document for every order
D.Reference the customer from each order
Correct Answer: Reference the customer from each order
Explanation:
Referencing centralizes frequently changing customer data and avoids updating many duplicated copies.
Incorrect! Try again.
25A blog post contains an embedded array of comments that can grow without a practical limit. What is the primary modeling concern?
Embedding vs. Referencing
Medium
A.The post can no longer contain scalar fields
B.The post document may become excessively large
C.The comments become relational database rows
D.The comments automatically lose their identifiers
Correct Answer: The post document may become excessively large
Explanation:
Unbounded arrays can cause document growth and may eventually approach MongoDB's document size limit.
Incorrect! Try again.
26An employee has exactly one security profile. The security profile is sensitive, accessed only by administrators, and updated independently. How should it usually be modeled?
One-to-One Relationships
Medium
A.Duplicate it in all department documents
B.Store it separately with an employee reference
C.Combine all profiles into one global array
D.Embed it in every employee query result
Correct Answer: Store it separately with an employee reference
Explanation:
A separate referenced document supports independent access control, retrieval, and updates for the security profile.
Incorrect! Try again.
27A vehicle document has one engine specification object that is always displayed with the vehicle and cannot exist independently. Which design is most appropriate?
One-to-One Relationships
Medium
A.Store the vehicle identifier inside every engine field
B.Embed the engine specification in the vehicle
C.Reference an engine collection from the vehicle
D.Create one collection for each engine property
Correct Answer: Embed the engine specification in the vehicle
Explanation:
Embedding fits a tightly coupled one-to-one relationship when the child data shares the parent's lifecycle.
Incorrect! Try again.
28A department has at most eight employees, and the department page always displays basic employee details. Which model favors a single read?
One-to-Many Relationships
Medium
A.Embed a bounded employee array in the department
B.Store departments and employees in unrelated databases
C.Reference the department from separate employee records
D.Create a department document for each employee
Correct Answer: Embed a bounded employee array in the department
Explanation:
A small, bounded array that is always read with its parent is a suitable use case for embedding.
Incorrect! Try again.
29A sensor produces millions of readings over time. Each reading belongs to one sensor, but readings are queried by date range. Which model is most scalable?
One-to-Many Relationships
Medium
A.Store only the latest reading for each sensor
B.Embed all readings in one sensor document
C.Duplicate each sensor for every date range
D.Store readings separately with a sensor reference
Correct Answer: Store readings separately with a sensor reference
Explanation:
A separate collection avoids an unbounded array and supports indexing readings by sensor and timestamp.
Incorrect! Try again.
30Orders embed line items because they are usually retrieved together. A product's name may later change, but old orders must preserve the purchased name. What should each line item store?
One-to-Many Relationships
Medium
A.The names of every product in the catalog
B.Only a live reference to the current product name
C.A snapshot of the product name at purchase time
D.No product information beyond the order identifier
Correct Answer: A snapshot of the product name at purchase time
Explanation:
Embedding a historical snapshot preserves the exact product information recorded when the order was created.
Incorrect! Try again.
31Students can enroll in many courses, and each course can contain many students. Enrollment also stores grade and enrolledAt. What is the best model?
Many-to-Many Relationships
Medium
A.Use an enrollment collection referencing both entities
B.Embed every student document inside each course
C.Embed every course document inside each student
D.Store grades directly in the database name
Correct Answer: Use an enrollment collection referencing both entities
Explanation:
An intermediate enrollment collection naturally represents the relationship and stores attributes such as grade and enrollment date.
Incorrect! Try again.
32Articles can have many tags, and tags can belong to many articles. The application mainly retrieves articles by tag. Which index is most useful when article documents store an array named tagIds?
Many-to-Many Relationships
Medium
A.A geospatial index on tagIds
B.A multikey index on tagIds
C.A TTL index on the article title
D.A text index on article _id
Correct Answer: A multikey index on tagIds
Explanation:
MongoDB creates a multikey index for an indexed array field, improving queries that match articles by a tag identifier.
Incorrect! Try again.
33Authors and books have a many-to-many relationship. Book pages are requested far more often than author pages, and each book has only a few authors. Which representation best supports the main access pattern?
Many-to-Many Relationships
Medium
A.Place all authors and books in one document
B.Create a separate database for each author
C.Store author references in each book document
D.Store complete books inside every author document
Correct Answer: Store author references in each book document
Explanation:
Keeping a small array of author references in each book supports frequent book-page retrieval without duplicating full author data.
Incorrect! Try again.
34A team is designing a MongoDB schema for an analytics application. Which factor should most strongly influence whether related data is embedded or referenced?
Data Modeling Best Practices
Medium
A.The application's common query and update patterns
B.The number of developers using the database
C.The visual length of the document fields
D.The alphabetical order of collection names
Correct Answer: The application's common query and update patterns
Explanation:
MongoDB schemas should be designed around how the application reads, writes, and updates related data.
Incorrect! Try again.
35A collection frequently executes queries using customerId and a descending createdAt sort. Which index is the best starting choice?
Data Modeling Best Practices
Medium
A.A compound index on { customerId: 1, createdAt: -1 }
B.A text index on { customerId: "text" }
C.A TTL index on { createdAt: 1 }
D.A single-field index on { status: 1 }
Correct Answer: A compound index on { customerId: 1, createdAt: -1 }
Explanation:
The compound index matches the equality filter on customerId and the requested descending order of createdAt.
Incorrect! Try again.
36A customer document contains a growing orders array, causing frequent document movement and slow updates. Which redesign is most appropriate?
Data Modeling Best Practices
Medium
A.Replace the orders array with one long string
B.Increase every order field to a larger data type
C.Move orders to a collection with customerId references
D.Duplicate the customer document for each update
Correct Answer: Move orders to a collection with customerId references
Explanation:
Separating an unbounded one-to-many relationship prevents excessive parent-document growth and supports efficient order queries.
Incorrect! Try again.
37An e-commerce order must preserve item prices as they were at checkout, even if catalog prices later change. Which schema feature best meets this requirement?
Case Studies and Examples
Medium
A.Read the current price from the product collection
B.Embed the checkout price in each order item
C.Calculate all historical prices from product ratings
D.Store one current price in the customer document
Correct Answer: Embed the checkout price in each order item
Explanation:
An embedded price snapshot preserves historical order accuracy independently of later catalog changes.
Incorrect! Try again.
38A social application displays a user's latest 10 notifications on every login but retains older notifications for auditing. Which design balances fast access and long-term growth?
Case Studies and Examples
Medium
A.Store all users' notifications in one shared array
B.Delete every notification after it has been displayed
C.Embed recent notifications and reference archived ones
D.Embed all notifications forever in the user document
Correct Answer: Embed recent notifications and reference archived ones
Explanation:
A hybrid model keeps the bounded working set close to the user while moving unbounded historical data to a separate collection.
Incorrect! Try again.
39A collection validator uses $jsonSchema to require email and specify that it must be a string. Which document violates the validator?
Validation Rules and Constraints
Medium
A.{ "email": "sam@example.com", "age": 21 }
B.{ "email": "lee@example.com", "active": true }
C.{ "name": "Ravi", "email": 42 }
D.{ "name": "Ravi", "email": "ravi@example.com" }
Correct Answer: { "name": "Ravi", "email": 42 }
Explanation:
The document includes email, but its value is numeric rather than the required string type.
Incorrect! Try again.
40A team adds a validator to a collection containing legacy documents. It wants new and modified documents checked, while existing documents may remain unchanged until updated. Which validationLevel should be used?
Validation Rules and Constraints
Medium
A.moderate
B.off
C.strict
D.warning
Correct Answer: moderate
Explanation:
The moderate level applies validation to inserts and to updates of documents that already satisfy the validator, allowing invalid legacy documents to remain until addressed.
Incorrect! Try again.
41A rolling deployment changes customer.address from a string to an object. Millions of legacy documents still use the old representation, and deployments cannot pause writes. Which migration strategy best preserves availability and schema correctness?
Schema-less Nature of MongoDB
Hard
A.Write both representations indefinitely, query either representation, and avoid adding schema validation.
B.Require the object representation immediately, reject legacy documents, and backfill after deployment.
C.Backfill while old writers remain active, then deploy readers that support only the new representation.
D.Read both representations, write the new representation, backfill legacy data, then tighten validation.
Correct Answer: Read both representations, write the new representation, backfill legacy data, then tighten validation.
Explanation:
This expand-and-contract migration prevents old documents or rolling application versions from breaking. Validation is tightened only after writers and stored data have converged.
Incorrect! Try again.
42A collection stores purchase, login, and shipment events with different required fields. Queries always specify the event type before filtering subtype-specific fields. Which design best supports controlled polymorphism and efficient indexing?
Schema-less Nature of MongoDB
Hard
A.Use no discriminator, infer each subtype from its fields, and create global indexes for every field.
B.Place subtype fields in one fixed structure, assign missing fields null, and use sparse indexes.
C.Store each event as an encoded string, validate it in application code, and index the entire string.
D.Use a discriminator, type-specific validation branches, and partial indexes restricted by event type.
Correct Answer: Use a discriminator, type-specific validation branches, and partial indexes restricted by event type.
Explanation:
A discriminator makes document variants explicit. Type-specific validation controls each shape, while partial indexes avoid indexing irrelevant documents.
Incorrect! Try again.
43An amount field contains integers, decimal values, and numeric strings because different application versions wrote different BSON types. Range queries and sorting must have numeric semantics. What is the most robust remedy?
Schema-less Nature of MongoDB
Hard
A.Normalize stored values to one numeric type and add validation preventing incompatible future values.
B.Convert query boundaries to strings because lexical ordering is equivalent for all numeric values.
C.Rely on BSON type ordering and convert each result to a number after the query completes.
D.Add separate indexes for every BSON type and merge the independently sorted result sets.
Correct Answer: Normalize stored values to one numeric type and add validation preventing incompatible future values.
Explanation:
Mixed BSON types follow type-aware comparison rules rather than uniform numeric semantics. Normalization restores correct ranges and validation prevents recurrence.
Incorrect! Try again.
44A popular article can receive millions of comments. Comments are paginated, moderated independently, and rarely fetched with the article body. Which model is most appropriate?
Embedding vs. Referencing
Hard
A.Embed every comment in the article and use array slicing to return each requested page.
B.Store article identifiers inside one global comments array and scan it for matching comment entries.
C.Store comments separately with articleId and index the fields used for pagination and moderation.
D.Embed recent comments and permanently discard older comments when the array reaches a fixed size.
Correct Answer: Store comments separately with articleId and index the fields used for pagination and moderation.
Explanation:
An unbounded embedded array risks the document size limit, relocation costs, and write contention. Referenced comments support independent paging and updates.
Incorrect! Try again.
45An order service must atomically append a line item and update the order's stored subtotal without using a multi-document transaction. Which model directly enables this guarantee?
Embedding vs. Referencing
Hard
A.Reference line-item documents and update the order subtotal through a later change-stream consumer.
B.Embed order identifiers in line items and calculate the subtotal whenever the order is subsequently read.
C.Reference line-item documents and issue two unordered writes using the same application request identifier.
D.Embed line items in the order and update the array and subtotal in one document operation.
Correct Answer: Embed line items in the order and update the array and subtotal in one document operation.
Explanation:
MongoDB guarantees atomicity at the single-document level. Embedding places the line items and subtotal inside the same atomic update boundary.
Incorrect! Try again.
46Each employee has at most one security-clearance record. Clearance data is large, rarely read, and protected by stricter authorization than ordinary employee data. Which design best matches these requirements?
One-to-One Relationships
Hard
A.Store clearance data separately, reference the employee, and enforce a unique index on employeeId.
B.Embed clearance data in every employee document and exclude it through projections for ordinary reads.
C.Store employee data inside the clearance document and duplicate it whenever employee information changes.
D.Place both records in one polymorphic collection without a discriminator or relationship constraint.
Correct Answer: Store clearance data separately, reference the employee, and enforce a unique index on employeeId.
Explanation:
Separation avoids loading sensitive data unnecessarily and permits distinct access controls. A unique index enforces the at-most-one side of the relationship.
Incorrect! Try again.
47A users collection and a profiles collection implement an optional one-to-one relationship. Which database mechanism guarantees that no user can have two profile documents, assuming profiles store userId?
One-to-One Relationships
Hard
A.A sparse index on users._id, combined with application-side checking before inserting a profile.
B.A regular index on profiles.userId, combined with a schema validator requiring an object identifier.
C.A unique index on profiles.userId, with an appropriate partial filter if the field is optional.
D.A schema validator on users._id, combined with majority read concern during profile creation.
Correct Answer: A unique index on profiles.userId, with an appropriate partial filter if the field is optional.
Explanation:
Schema validation cannot enforce uniqueness across documents. A unique index on the referencing field guarantees at most one matching profile.
Incorrect! Try again.
48A sensor emits 20 readings per second indefinitely. Each reading averages 400 bytes before indexing, and most queries retrieve 15-minute intervals. Which model best controls document growth while preserving locality?
One-to-Many Relationships
Hard
A.Store one ever-growing bucket per sensor and rely on compression to avoid the BSON document size limit.
B.Embed all readings in the sensor document because one-to-many relationships should always be colocated.
C.Create one document per reading and omit the sensor identifier because timestamps uniquely identify readings.
D.Create bounded time buckets containing about readings per sensor and interval.
Correct Answer: Create bounded time buckets containing about readings per sensor and interval.
Explanation:
Time bucketing limits array and document growth while retaining locality for interval queries. Bucket size must still be checked against the 16 MB BSON limit.
Incorrect! Try again.
49A customer can have at most 12 delivery addresses. Addresses are owned exclusively by that customer, usually loaded with the customer, and updated together with customer preferences. Which model is strongest?
One-to-Many Relationships
Hard
A.Store customer data inside each address and select an arbitrary address as canonical.
B.Embed the addresses as a bounded array within the customer document.
C.Store addresses separately and execute a $lookup for every customer read.
D.Place all customers' addresses in one shared document grouped by postal code.
Correct Answer: Embed the addresses as a bounded array within the customer document.
Explanation:
The relationship is bounded, privately owned, and commonly accessed together. Embedding improves locality and supports atomic updates with customer preferences.
Incorrect! Try again.
50Support tickets belong to one account at a time but are frequently reassigned, queried independently, and retained after an account is deleted. Which representation best supports these operations?
One-to-Many Relationships
Hard
A.Embed tickets in account documents and move array elements between accounts during reassignment.
B.Store ticket identifiers in account arrays and use those arrays as the only ownership records.
C.Store tickets separately with accountId and index fields such as accountId and status.
D.Duplicate complete ticket documents in both the old and new accounts whenever reassignment occurs.
Correct Answer: Store tickets separately with accountId and index fields such as accountId and status.
Explanation:
Independent lifecycle, reassignment, and direct querying favor child-side references. Indexing the foreign key and query fields makes account-specific retrieval efficient.
Incorrect! Try again.
51Students enroll in courses, and each enrollment has grade, enrolledAt, and status. The system must prevent duplicate active enrollment pairs and query efficiently from either side. Which design is best?
Many-to-Many Relationships
Hard
A.Store only student identifiers in courses and scan every course when retrieving one student's enrollments.
B.Embed complete course documents in students and complete student documents in courses for every enrollment.
C.Store only course identifiers in students and calculate enrollment attributes from the array positions.
D.Use an enrollment collection with a unique compound student-course index and a reverse lookup index.
Correct Answer: Use an enrollment collection with a unique compound student-course index and a reverse lookup index.
Explanation:
The enrollment is an association entity because it has attributes. A compound unique index prevents duplicate pairs, while an alternate index supports reverse traversal.
Incorrect! Try again.
52An undirected friendship must treat (A, B) and (B, A) as the same relationship while rejecting self-friendship. Which representation enforces this most reliably?
Many-to-Many Relationships
Hard
A.Store both directional documents and periodically remove duplicates using a scheduled aggregation.
B.Store identifiers in arbitrary order and create separate unique indexes on each individual identifier.
C.Store the lower identifier first, add a unique compound index, and reject equal identifiers.
D.Store friend identifiers in both user documents and rely on application retries to preserve symmetry.
Correct Answer: Store the lower identifier first, add a unique compound index, and reject equal identifiers.
Explanation:
Canonical ordering converts both directions into one key. The compound unique index prevents duplicate edges, and validation rejects self-relationships.
Incorrect! Try again.
53A proposed enrollment document contains both a studentIds array and a courseIds array. The team wants one compound index covering both fields. What is the best redesign?
Many-to-Many Relationships
Hard
A.Retain both arrays and use a wildcard index because wildcard indexes remove parallel-array restrictions.
B.Retain both arrays and declare the compound index as sparse so MongoDB ignores excess array entries.
C.Convert both arrays to comma-separated strings and create a compound text index over the strings.
D.Create one enrollment edge per student-course pair and index the two scalar identifiers.
Correct Answer: Create one enrollment edge per student-course pair and index the two scalar identifiers.
Explanation:
A compound multikey index cannot index parallel arrays in the same document. Scalar edge documents also represent each many-to-many association without ambiguity.
Incorrect! Try again.
54A messaging system stores millions of messages per conversation. The dominant query retrieves the newest 50 messages for one conversation, while participant metadata is small and stable. Which model and index best fit the query?
Data Modeling Best Practices
Hard
A.Store each participant's copy of every message and index only the sender identifier.
B.Embed every message in the conversation and index the nested message timestamp array.
C.Store all messages in daily global documents and index each day's embedded message array.
D.Store messages separately and index {conversationId: 1, createdAt: -1}.
Correct Answer: Store messages separately and index {conversationId: 1, createdAt: -1}.
Explanation:
Separate messages avoid unbounded conversation documents. The compound index supports equality on the conversation and ordered retrieval by creation time.
Incorrect! Try again.
55A service maintains a materialized event counter, but event delivery is at least once and consumers may retry after uncertain failures. Which design best prevents double counting?
Data Modeling Best Practices
Hard
A.Use an atomic counter increment because atomicity automatically deduplicates repeated event identifiers.
B.Read the counter before every increment and reject an event when the counter has recently changed.
C.Increment the counter for every delivery and periodically estimate duplicates from matching timestamps.
D.Insert a unique event marker and increment the counter in one transaction only for a new marker.
Correct Answer: Insert a unique event marker and increment the counter in one transaction only for a new marker.
Explanation:
The unique event marker supplies idempotency, and the transaction couples deduplication with the increment. A duplicate marker causes the entire repeated operation to abort.
Incorrect! Try again.
56An e-commerce order must preserve the product name, tax category, and unit price as they existed at checkout, while still allowing navigation to the current product. Which model is most appropriate?
Case Studies and Examples
Hard
A.Store only the product name and price because retaining a product identifier creates unnecessary coupling.
B.Embed the complete current product record and synchronize every historical order after product updates.
C.Embed a purchase-time product snapshot in each line item and retain productId as a reference.
D.Store only productId and always join the current product record when displaying historical orders.
Correct Answer: Embed a purchase-time product snapshot in each line item and retain productId as a reference.
Explanation:
Historical facts should not change with the product catalog. A snapshot preserves checkout semantics, while the identifier links to the current product.
Incorrect! Try again.
57A social network precomputes home feeds. Fan-out-on-write works for ordinary accounts, but celebrity posts would require millions of immediate writes. Which strategy best handles both workloads?
Case Studies and Examples
Hard
A.Use fan-out-on-write normally but merge celebrity posts at read time using a hybrid feed.
B.Use fan-out-on-write for every account and increase the write concern for celebrity posts.
C.Use fan-out-on-read for every account and scan all followed accounts for each feed request.
D.Embed every follower's feed inside the celebrity document and paginate the resulting nested arrays.
Correct Answer: Use fan-out-on-write normally but merge celebrity posts at read time using a hybrid feed.
Explanation:
The hybrid approach preserves fast reads for ordinary accounts while avoiding extreme write amplification for high-fan-out celebrity posts.
Incorrect! Try again.
58A multi-tenant order platform has several very large tenants. Every request contains tenantId, order identifiers are nonsequential, and references must not cross tenants accidentally. Which strategy is strongest?
Case Studies and Examples
Hard
A.Shard by creation time, store tenantId only in users, and infer order tenancy through user references.
B.Shard only by order identifier, use global references, and filter tenant ownership in application memory.
C.Use tenantId plus a hashed orderId as the shard key and include tenantId in relationship keys.
D.Shard only by tenantId, omit it from references, and verify tenant ownership after each lookup.
Correct Answer: Use tenantId plus a hashed orderId as the shard key and include tenantId in relationship keys.
Explanation:
The compound key preserves tenant-aware routing while distributing large tenants across hashed order ranges. Including tenantId in references reduces cross-tenant access risks.
Incorrect! Try again.
59User email is optional, but every string-valued email must have valid syntax and be unique. Missing or null email values may occur many times. Which combination best enforces this requirement?
Validation Rules and Constraints
Hard
A.Use a syntax validator and a partial unique email index restricted to string-valued email fields.
B.Use a sparse unique email index alone because sparse indexes also validate email syntax and type.
C.Use a syntax validator alone because validation rules compare values across all documents automatically.
D.Use a required email validator and a regular unique index that includes missing and null values.
Correct Answer: Use a syntax validator and a partial unique email index restricted to string-valued email fields.
Explanation:
Validation controls type and syntax, while a partial unique index enforces uniqueness only for actual string emails. Cross-document uniqueness is not a validator capability.
Incorrect! Try again.
60A new validator is introduced on a collection containing legacy invalid documents. New inserts must comply, but unrelated updates to legacy invalid documents must remain possible during migration. Which setting has the required behavior?
Validation Rules and Constraints
Hard
A.Use validationLevel: "strict" and remove the validator from all application update operations.
B.Use validationLevel: "off" and validationAction: "warn" until every document is repaired.
C.Use validationLevel: "strict" and validationAction: "error" for every insert and update.
D.Use validationLevel: "moderate" and validationAction: "error" during the migration.
Correct Answer: Use validationLevel: "moderate" and validationAction: "error" during the migration.
Explanation:
Moderate validation checks new inserts and updates to already valid documents, while allowing updates to legacy documents that remain invalid. This supports gradual cleanup.
Incorrect! Try again.
Did this save you a night before the exam?
LPU Notes is free, and it stays free. Ads cover part of the server bill.
The rest comes out of a student's own pocket: the domain, the storage,
and keeping the site up through the weeks everyone needs it at once.
The payment button didn't load. An ad blocker or a filtered network is the usual reason.
to try again.
Nothing here is ever locked, and nothing unlocks. Chip in only if it was worth it.
What it pays for →