MongoDB Data Modeler Associate study materials
MongoDB Data Modeler Associate study resources

MongoDB Data Modeler Associate practice questions

One question at a time. Build your MongoDB Data Modeler Associate understanding.

First 50 of 200 questions. Each one lists the choices, the correct answer, and an explanation. The checker at the top of this page saves progress in this browser when it is available.

Continue in the practice tool above to load more questions, 50 at a time.

Question 1Data Modeling

In a MongoDB schema, which structure stores related fields as nested key-value pairs inside a single document rather than as separate documents in a collection?

  1. A sharded cluster
  2. A capped collection
  3. A time-series collection
  4. An embedded document Correct answer.

Explanation

Embedding places related data inside the parent document as a nested sub-document, so one read retrieves the whole object. Capped and time-series collections are collection-level storage types, and a sharded cluster is a deployment topology, not a document structure.

Question 2Data Modeling

A modeling team needs each order document to reference the customer who placed it while keeping order documents small. Which field type best expresses that reference?

  1. An array of embedded customer sub-documents
  2. A gridFS bucket identifier
  3. A text index on the customer name
  4. A scalar field holding the customer's _id value Correct answer.

Explanation

A reference stores the related document's unique identifier in a scalar field, keeping the parent document compact and avoiding duplication. Embedding the full customer copies data, gridFS is for large binary files, and a text index is a query structure rather than a reference.

Question 3Data Modeling

Which BSON type should a modeler choose for a field whose values are only ever true or false, such as a shipped flag?

  1. ObjectId
  2. Boolean Correct answer.
  3. Decimal128
  4. String

Explanation

The BSON boolean type stores exactly two values and is the natural fit for flags. String would allow arbitrary text, Decimal128 is for high-precision numbers, and ObjectId is a 12-byte identifier type.

Question 4Data Modeling

What is the maximum size of a single BSON document that MongoDB will store?

  1. 16 MB Correct answer.
  2. 8 MB
  3. 4 MB
  4. 64 MB

Explanation

MongoDB enforces a 16 megabyte limit on a single BSON document, which constrains how much data can be embedded in one record. Data that would exceed this limit should be split across documents or stored in gridFS.

Question 5Data Modeling

Which schema pattern stores a bounded, frequently accessed subset of related data inside the main document while the full set lives in another collection?

  1. The attribute pattern
  2. The subset pattern Correct answer.
  3. The schema versioning pattern
  4. The bucket pattern

Explanation

The subset pattern duplicates a small, hot portion of a related dataset into the main document to avoid extra reads, while the complete dataset remains in its own collection. The attribute, bucket, and schema versioning patterns solve different problems.

Question 6Data Modeling

A collection stores sensor readings where each document holds one reading. Modelers want to group many readings from the same sensor into a single document with a count and time range. Which pattern does this describe?

  1. The extended reference pattern
  2. The polymorphic pattern
  3. The bucket pattern Correct answer.
  4. The computed pattern

Explanation

The bucket pattern collects many individual measurements into one document per group, reducing document count and index size for high-volume time-series data. The other patterns address references, varying shapes, and precomputed values respectively.

Question 7Data Modeling

Which statement correctly describes how MongoDB enforces uniqueness on a field?

  1. A unique index on the field rejects duplicate values across documents. Correct answer.
  2. Uniqueness requires the field to be declared in a JSON schema validator.
  3. Every field is unique by default in a collection.
  4. Uniqueness is enforced only when the field is embedded in an array.

Explanation

Uniqueness in MongoDB is enforced through a unique index, which causes inserts and updates that would duplicate the indexed value to fail. Fields are not unique by default, and schema validators do not enforce cross-document uniqueness.

Question 8Data Modeling

When modeling an entity relationship in MongoDB, what does the cardinality of the relationship describe?

  1. The number of documents on each side of the relationship Correct answer.
  2. The number of indexes applied to the collection
  3. The average BSON size of each related document
  4. The read preference used to query the collection

Explanation

Cardinality describes how many documents participate on each side of a relationship, such as one-to-one, one-to-many, or many-to-many. It guides the choice between embedding and referencing.

Question 9Data Modeling

A product catalog must support queries that filter on many different optional attributes, and most documents omit most of those attributes. Which pattern best reduces the number of indexes needed?

  1. The attribute pattern Correct answer.
  2. The outlier pattern
  3. The versioning pattern
  4. The tree pattern

Explanation

The attribute pattern converts many sparse, optional fields into an array of key-value sub-documents, allowing a small number of indexes to cover searches across all attributes. The outlier, versioning, and tree patterns address different modeling concerns.

Question 10Data Modeling

An application must always read an order together with its line items, and line items are never queried independently. Which modeling choice is most appropriate?

  1. Embed line items as an array inside the order document Correct answer.
  2. Store line items in a gridFS bucket
  3. Reference line items from a separate collection by _id
  4. Shard line items into their own database

Explanation

When related data is always accessed together and is bounded in size, embedding it in the parent document satisfies the access pattern with a single read. Referencing adds a second query, and gridFS and separate databases do not match the access pattern.

Question 11Data Modeling

A social feed stores a post document and needs each post to show the author's display name without a second query, while the author profile remains the source of truth. Which pattern fits?

  1. The archive pattern
  2. The extended reference pattern Correct answer.
  3. The schema versioning pattern
  4. The bucket pattern

Explanation

The extended reference pattern copies a small set of frequently read fields from the referenced document into the parent, avoiding a lookup for common reads. The author profile stays authoritative and can be updated separately.

Question 12Data Modeling

A collection holds documents for several product categories whose fields differ substantially, and queries usually filter by category first. Which approach keeps a single collection while handling the varying shapes?

  1. Store each category's fields in a separate database
  2. Create one collection per category and never query across them
  3. Convert all fields to strings to unify the shape
  4. Use a discriminator field plus a JSON schema that branches on its value Correct answer.

Explanation

A discriminator field identifies the document's shape, and a JSON schema can apply different validation rules per value, supporting the polymorphic pattern in one collection. Splitting collections or databases complicates cross-category queries, and stringifying fields loses type information.

Question 13Data Modeling

A dashboard repeatedly computes a total from an array of line items on every read. Which pattern stores the total alongside the items and updates it when the array changes?

  1. The outlier pattern
  2. The single collection pattern
  3. The computed pattern Correct answer.
  4. The tree pattern

Explanation

The computed pattern precalculates and persists a derived value so reads avoid repeated computation. The application must update the stored value whenever the source data changes.

Question 14Data Modeling

A modeler is designing an index for queries that filter on status and sort by createdAt. Which compound index best supports that access pattern?

  1. { createdAt: 1 }
  2. { status: 1 }
  3. { createdAt: 1, status: 1 }
  4. { status: 1, createdAt: 1 } Correct answer.

Explanation

A compound index should list equality-filtered fields before sort fields so the index can serve both the filter and the sort. Putting status first and createdAt second matches the query shape.

Question 15Data Modeling

What is the recommended approach when a one-to-many relationship could grow to thousands of child documents per parent?

  1. Duplicate the parent document for every child
  2. Store children in a capped collection keyed by parent
  3. Embed all children in an unbounded array in the parent
  4. Reference children from the parent or store the parent _id on each child Correct answer.

Explanation

Unbounded arrays risk hitting the 16 MB document limit and degrade update performance, so referencing keeps documents bounded. Storing the parent identifier on each child supports efficient queries by parent.

Question 16Data Modeling

A team stores monetary amounts as BSON double. Which change best preserves exact decimal precision for financial calculations?

  1. Store the amount as a string with a currency symbol
  2. Store the amount as a boolean flag
  3. Switch the field to Decimal128 Correct answer.
  4. Switch the field to a 32-bit integer

Explanation

Decimal128 is a 128-bit decimal floating-point type designed for exact decimal arithmetic, avoiding binary floating-point rounding in financial data. Integers, strings, and booleans do not represent fractional currency precisely.

Question 17Data Modeling

Which schema design most directly supports the access pattern of retrieving the most recent 20 events for a user with a single indexed query?

  1. Store events in a separate collection indexed on { userId: 1, timestamp: -1 } Correct answer.
  2. Store events in a gridFS bucket named after the user
  3. Store each event as a top-level field named by its timestamp
  4. Embed all events in the user document in insertion order

Explanation

A separate events collection with a compound index on userId and descending timestamp lets the database seek directly to a user's newest events and stop after 20. Embedding all events risks unbounded growth, and the other options do not support ordered range queries.

Question 18Data Modeling

A modeler wants documents to record which version of the schema they were written with so the application can handle older shapes during migration. Which pattern applies?

  1. The subset pattern
  2. The schema versioning pattern Correct answer.
  3. The computed pattern
  4. The bucket pattern

Explanation

The schema versioning pattern adds a version field to documents so readers can interpret or transform multiple shapes during a gradual migration. The subset, bucket, and computed patterns serve other purposes.

Question 19Data Modeling

Which statement best explains why denormalizing a frequently read field into a parent document introduces a consistency trade-off?

  1. Denormalized fields cannot be indexed at all
  2. Denormalized fields always exceed the 16 MB document limit
  3. The copied value must be updated in every document that holds it when the source changes Correct answer.
  4. Denormalized fields prevent the use of transactions

Explanation

Duplicating a field means every copy must be synchronized when the authoritative value changes, otherwise readers see stale data. This is the core trade-off of denormalization: faster reads in exchange for update complexity.

Question 20Data Modeling

A workload requires atomic updates across two collections that hold separately referenced documents. Which capability most directly supports this requirement?

  1. A unique index on both collections
  2. A capped collection for each entity
  3. A text index spanning both collections
  4. A multi-document transaction Correct answer.

Explanation

Multi-document transactions provide atomicity across operations on multiple documents and collections. Indexes improve query performance but do not provide atomicity, and capped collections and text indexes do not span collections transactionally.

Question 21Data Modeling

A collection contains a small number of documents with an unusually large array that inflates index size for all queries. Which pattern isolates those documents so typical documents stay lean?

  1. The extended reference pattern
  2. The attribute pattern
  3. The outlier pattern Correct answer.
  4. The schema versioning pattern

Explanation

The outlier pattern moves rare, problematic documents into a separate collection or flags them so the main collection stays optimized for the common case. The other patterns address sparse attributes, duplicated reference fields, and schema evolution.

Question 22Data Modeling

A modeler must choose between embedding and referencing for a many-to-many relationship between students and courses where both sides are queried independently and enrollments change often. Which choice is most defensible?

  1. Embed all enrollments as a single array in one shared document
  2. Reference courses from students and maintain the relationship in a separate enrollment collection Correct answer.
  3. Store both entities in a capped collection to avoid duplicates
  4. Embed course documents inside each student and student documents inside each course

Explanation

Many-to-many relationships with independent access and frequent changes are best modeled with references, often through a join-style collection that records each pairing. Duplicating both sides creates synchronization problems and unbounded arrays.

Question 23Data Modeling

An application stores a user's address both embedded in the user document and referenced by orders. When the address changes, which design decision most reduces stale reads in order history?

  1. Store only the address _id in orders and resolve it at read time Correct answer.
  2. Delete the address from the user document after the first order
  3. Store a full copy of the address in each order and never update it
  4. Embed the address in orders and also keep it in the user document as the source of truth

Explanation

Referencing the address by identifier keeps a single authoritative copy, so updates propagate to all readers and order history reflects current data. Copying the address into orders creates duplicates that go stale unless explicitly synchronized.

Question 24Data Modeling

A team needs to store a product's variable specifications, where each product may have dozens of differently named attributes and queries filter on attribute name and value. Which design best supports those queries with minimal indexing?

  1. An array of { k: name, v: value } sub-documents indexed on both keys Correct answer.
  2. One top-level field per attribute name
  3. A single concatenated string of all attributes
  4. A separate collection per attribute name

Explanation

The attribute pattern stores variable attributes as key-value sub-documents in an array, and a compound index on the key and value fields supports queries across all attribute names. Top-level fields per attribute and per-attribute collections multiply indexes and complexity.

Question 25Data Modeling

Which consideration most strongly favors embedding over referencing when modeling a one-to-few relationship?

  1. The child documents are updated by many independent services at high frequency
  2. The child documents are always read together with the parent and the array stays small Correct answer.
  3. The child documents must be queried without the parent by a separate application
  4. The child documents are expected to grow without a known bound

Explanation

Embedding works well when children are read with the parent and the array remains bounded, giving single-read access without size risk. Frequent independent updates, parent-independent queries, and unbounded growth all favor referencing.

Question 26Data Modeling

In MongoDB, which BSON type should a modeler choose for a field that must store whole numbers larger than what a 32-bit integer can hold?

  1. Int32
  2. Decimal128
  3. Double
  4. Long (64-bit integer) Correct answer.

Explanation

The BSON long type is a signed 64-bit integer, so it can hold values far beyond the 32-bit int range without loss. Double stores floating-point values and can lose exactness for large integers, and Decimal128 is intended for precise decimal arithmetic rather than plain integer storage.

Question 27Data Modeling

A modeler is documenting a schema where each document must contain a field whose value is a list of tag strings. Which BSON type represents that field?

  1. Object
  2. Binary
  3. String
  4. Array Correct answer.

Explanation

A BSON array holds an ordered list of values, which is how MongoDB stores a field containing multiple tags. Each element can itself be any BSON type, so an array of strings is a natural fit for a list of tags.

Question 28Data Modeling

Which statement describes the role of the _id field in every MongoDB document?

  1. It is optional and only created when the modeler defines it.
  2. It is shared across all documents in a database to enforce referential integrity.
  3. It is a required field that uniquely identifies the document within its collection. Correct answer.
  4. It must be a string generated by the driver before insert.

Explanation

Every document stored in a collection must have an _id field, and its value must be unique within that collection. If the application does not supply one, the driver generates an ObjectId automatically at insert time.

Question 29Data Modeling

A modeler wants to store a monetary price as an exact decimal value rather than a binary floating-point approximation. Which BSON type is designed for this?

  1. Symbol
  2. Decimal128 Correct answer.
  3. Double
  4. Int64

Explanation

Decimal128 stores base-10 decimal values with high precision, so amounts such as 19.99 are represented exactly instead of as binary approximations. It is the recommended type when exact decimal arithmetic matters, as with currency.

Question 30Data Modeling

Which statement best describes the difference between embedding a subdocument and referencing another document?

  1. Embedding creates an automatic index on the child data, while referencing does not.
  2. Referencing duplicates data in both collections, while embedding avoids all duplication.
  3. Referencing requires a transaction, while embedding always requires a separate collection.
  4. Embedding stores related data inside the parent document, while referencing stores a link such as an _id to a document in another collection. Correct answer.

Explanation

Embedding places the related data physically inside the parent document so it is read in a single query, while referencing keeps the related data in a separate collection and stores a pointer such as the target's _id. The choice trades read locality against duplication and document size.

Question 31Data Modeling

A modeler is choosing between a one-to-one relationship embedded in the parent document and one split into a separate collection. Which factor most directly supports embedding the related data?

  1. The related data is large and rarely accessed with the parent.
  2. The related data is always read together with the parent and is small. Correct answer.
  3. The related data must be updated independently by many writers.
  4. The related data must be queried on its own by a separate service.

Explanation

Embedding works well when the related data is small and is usually needed whenever the parent is read, because one query returns everything. If the data is large, rarely used with the parent, or queried independently, a separate collection is usually better.

Question 32Data Modeling

Which practice helps a modeler keep a schema readable as an application evolves?

  1. Using consistent field naming and a documented schema version field. Correct answer.
  2. Storing every field under a single nested object with generic names.
  3. Omitting field names and relying on array position.
  4. Allowing each document to use different field names for the same concept.

Explanation

Consistent naming and a documented schema version make documents easier to interpret and let the application handle older shapes during migrations. Field names carry meaning in MongoDB, so reusing one name for one concept across documents reduces ambiguity.

Question 33Data Modeling

A modeler needs to store a document's creation time so that it can be sorted and queried efficiently. Which BSON type is the natural choice?

  1. Date Correct answer.
  2. Timestamp
  3. String
  4. ObjectId

Explanation

The BSON Date type stores a 64-bit integer of milliseconds since the Unix epoch, which supports range queries and sorting. Storing dates as strings requires parsing and does not sort chronologically unless carefully formatted.

Question 34Data Modeling

A blog application stores posts and comments. Each post has a modest number of comments that are always displayed with the post, and comments are never queried on their own. Which schema best fits this access pattern?

  1. Store each comment in its own collection and duplicate the post in each comment.
  2. Store comments in a single shared document that all posts reference.
  3. Embed comments as an array of subdocuments inside the post document. Correct answer.
  4. Store comments in a separate collection and reference them from each post.

Explanation

When comments are few, always read with the post, and never queried independently, embedding them as an array returns the whole page in one read. This matches the one-to-few pattern where the child data is bounded and read with the parent.

Question 35Data Modeling

An e-commerce modeler must store order line items that can reach thousands per order and are sometimes queried independently for fulfillment. Which approach best fits these requirements?

  1. Store line items in a separate collection with an orderId field referencing the order. Correct answer.
  2. Store each line item as a top-level field named by its position.
  3. Embed all line items in the order document regardless of size.
  4. Store line items in a capped collection shared by all orders.

Explanation

A separate collection keeps the order document bounded and lets fulfillment query line items directly by orderId. Embedding thousands of items risks hitting the 16 MB document limit and forces every order read to load data that is not always needed.

Question 36Data Modeling

A catalog has products whose specifications vary widely: one product has screen size and battery, another has fabric and size. A modeler wants to store these attributes without a fixed schema. Which approach is most flexible?

  1. A fixed set of columns for every possible attribute, with nulls where unused.
  2. A single string field concatenating all attribute names and values.
  3. An array of subdocuments each holding a key and value, or a subdocument whose keys are the attribute names. Correct answer.
  4. A separate collection with one document per attribute name shared by all products.

Explanation

MongoDB's document model allows a subdocument or an array of key-value pairs to hold variable attributes without altering a fixed schema. This keeps each product's specifications self-contained and queryable by attribute name.

Question 37Data Modeling

A modeler is deciding how to represent a many-to-many relationship between articles and tags, where tags are shared across many articles and each article has a small number of tags. Which design best supports listing all articles that use a given tag?

  1. Store tag _ids in an array on each article and keep tags in their own collection. Correct answer.
  2. Store article _ids in an array on each tag only.
  3. Embed full tag documents in each article and query the embedded array.
  4. Store tags as top-level fields whose names are the tag strings.

Explanation

Storing tag _ids as an array on each article lets a query match the array to find articles for a tag, while the tags collection keeps each tag defined once. This avoids duplicating tag details and supports the shared many-to-many relationship.

Question 38Data Modeling

A user profile shows a list of the user's most recent 20 activity events. Events are written frequently and older events are rarely read. Which schema best supports this access pattern?

  1. Store each event in its own collection named after the user.
  2. Store events in a separate collection indexed by userId and timestamp, and query the latest 20. Correct answer.
  3. Store events in the user document as a single concatenated string.
  4. Embed all events in the user document without a limit.

Explanation

A separate events collection with a compound index on userId and timestamp supports efficient sorted retrieval of the newest events without unbounded document growth. Keeping the user document small avoids write contention and size limits as events accumulate.

Question 39Data Modeling

A modeler stores a user's current address embedded in the user document and also copies it into each order document at purchase time. What is the main modeling consequence of this duplication?

  1. The embedded address in orders can become stale if the user later changes their address. Correct answer.
  2. MongoDB automatically synchronizes the two copies on every update.
  3. The order document can no longer be queried by user.
  4. The duplication prevents any index from being created on the address field.

Explanation

Duplicating data means each copy must be updated separately, so a later address change leaves older order copies unchanged. In this case that may be intentional, because the shipping address at purchase time should be preserved as a historical record.

Question 40Data Modeling

A modeler wants to record, in each document, which version of the application schema produced it so that readers can handle older shapes. Which approach is most direct?

  1. Encode the version in the collection name and create one collection per version.
  2. Store the version only in a separate configuration collection.
  3. Add an explicit schemaVersion field to each document. Correct answer.
  4. Rely on the ObjectId timestamp to infer the schema version.

Explanation

An explicit schemaVersion field travels with each document, so the application can branch on the version when reading or migrating. Inferring from ObjectId timestamps is unreliable because inserts and schema changes do not align precisely.

Question 41Data Modeling

A modeler needs to store a product's price history as a bounded list of recent price changes, and each change has a date and an amount. Which representation best fits this need?

  1. An array of subdocuments, each with date and amount fields. Correct answer.
  2. A top-level field for each date, named with the date string.
  3. A single string field containing all price changes.
  4. A separate collection with one document per product shared by all products.

Explanation

An array of subdocuments keeps each price change as a structured object with its own date and amount, which can be queried and projected. Bounding the array by keeping only recent changes avoids unbounded document growth.

Question 42Data Modeling

A modeler is designing a collection where documents represent invoices, and each invoice must include a snapshot of the customer's tax identifier at issue time even though the customer record may change later. Which design meets this requirement?

  1. Reference the customer document and read the tax identifier at query time.
  2. Store the tax identifier in a global settings collection.
  3. Embed the tax identifier value in the invoice document at creation. Correct answer.
  4. Store the tax identifier only in the customer collection.

Explanation

Embedding the tax identifier value at creation captures the value as it was when the invoice was issued, independent of later customer changes. Referencing would return the current value, which may differ from the value at issue time.

Question 43Data Modeling

A modeler must store a set of optional attributes where different documents have different subsets of the same attribute names. Which design keeps queries simple while supporting optional attributes?

  1. A single array of values with no attribute names.
  2. A separate collection with one document per attribute value shared globally.
  3. A subdocument whose keys are the attribute names, present only when set. Correct answer.
  4. A fixed set of fields where unused attributes are set to the string "null".

Explanation

Using a subdocument keyed by attribute name lets each document include only the attributes it has, and queries can address attributes by dotted path. This avoids storing placeholder values and keeps the schema flexible.

Question 44Data Modeling

A modeler is choosing between embedding and referencing for a relationship where the child data changes frequently and is read on its own by another service. Which choice is most appropriate?

  1. Reference the child data from a separate collection. Correct answer.
  2. Store the child data in a single shared document for all parents.
  3. Duplicate the child data in both the parent and a separate collection.
  4. Embed the child data in the parent to reduce queries.

Explanation

When child data changes frequently and is read independently, a separate collection avoids duplicating it and lets the other service query it directly. Embedding would force updates to every parent that contains a copy.

Question 45Data Modeling

A modeler stores a document with a field that must hold one of a small fixed set of string values, such as "pending", "shipped", or "delivered". Which design best supports querying and indexing by that state?

  1. A string field restricted by the application to the allowed values. Correct answer.
  2. A boolean field for each possible state.
  3. A subdocument whose keys are the state names and values are true or false.
  4. An integer field whose meaning is documented outside the database.

Explanation

A single string field holding one of the allowed values is simple to query and index, and the application enforces the allowed set. MongoDB does not enforce enums natively, so validation can be added with schema validation if needed.

Question 46Data Modeling

A modeler is deciding how to store a user's list of favorite product _ids, which can grow to several thousand and is read with the user profile. Which design is most appropriate?

  1. Store favorites in a separate collection with one document per favorite.
  2. Embed the full product documents in the user document.
  3. Store an array of product _ids in the user document and keep products in their own collection. Correct answer.
  4. Store the user _id in an array on each product only.

Explanation

An array of _ids keeps the user document bounded and lets the profile return favorites in one read, while products remain defined once in their own collection. Storing only user _ids on products would require scanning products to build a user's list.

Question 47Data Modeling

A modeler is designing a schema for a workload where documents for different entity types share a collection and queries filter on a common field present in all types. What is the main trade-off of this polymorphic design?

  1. It prevents any index from being created on the shared field.
  2. It allows one collection and shared indexes, but documents must be validated for their type by the application. Correct answer.
  3. It requires a separate collection for each type to support the shared field.
  4. It forces every document to contain every field used by any type.

Explanation

A shared collection lets different document shapes coexist and share indexes on common fields, but MongoDB does not enforce per-type shapes, so the application must validate each type. This is the core trade-off of polymorphic schemas.

Question 48Data Modeling

A modeler needs to count how many orders each customer has placed, and the count is read on every customer page view. Which design best supports this requirement while keeping the count accurate as orders are added?

  1. Store the count in a separate collection updated only nightly.
  2. Maintain a counter field on the customer document and increment it when an order is created. Correct answer.
  3. Compute the count with a query on the orders collection on every page view.
  4. Store the count in the order document for each order.

Explanation

A maintained counter on the customer document turns a repeated aggregation into a single field read, which fits a read-heavy page view. The application must increment the counter in the same operation that creates the order to keep it accurate.

Question 49Data Modeling

A modeler is deciding how to model a relationship where each parent has a small, bounded number of children that are always updated together with the parent in one atomic operation. Which design best meets the atomicity requirement?

  1. Store the children in a shared collection keyed by child _id.
  2. Reference the children from a separate collection.
  3. Embed the children in the parent document. Correct answer.
  4. Store the children in a capped collection.

Explanation

A single-document write is atomic in MongoDB, so embedding the children lets the parent and its children be updated together atomically. Referencing across collections would require a multi-document transaction to achieve the same guarantee.

Question 50Data Modeling

A modeler observes that one document in a collection has grown to include a very large array, slowing reads of that document and inflating its indexes. Which redesign most directly addresses the problem?

  1. Store the array in a capped collection.
  2. Move the array elements into a separate collection referencing the parent. Correct answer.
  3. Add more indexes on the array elements.
  4. Convert the array to a single concatenated string.

Explanation

Moving a large, unbounded array into a separate collection keeps the parent document small and lets the elements be queried and indexed independently. This avoids document size limits and reduces the cost of reading the parent.