[{"id":"mongodbadvanced-001","courseId":"mongodb-advanced","domain":"data-modeling","topic":"Schema versioning pattern","prompt":"A product team changes the shape of order documents. Migrating millions of old documents would take weeks, and the app can't go down. They leave old documents as they are and add a schemaVersion field to each document. What does schemaVersion give the app?","hint":"Think about who reads the version field, and what happens to the old documents.","source":"https://www.mongodb.com/docs/manual/data-modeling/design-patterns/data-versioning/","interaction":{"type":"single"},"options":[{"id":"a","text":"The app can tell each document's shape and query it correctly, so old documents keep their original structure.","why":"The versioning pattern keeps historical documents in their original form, and schemaVersion tells the application how to query each one."},{"id":"b","text":"The server rewrites older documents to the new shape the next time they are read.","whyNot":"MongoDB does not migrate documents on read; avoiding that kind of migration is the point of the pattern."},{"id":"c","text":"The new app version must wait until every old document has been updated.","whyNot":"The pattern exists to avoid that downtime and the long migration it would require."},{"id":"d","text":"Queries skip every document whose schemaVersion is lower than the current one.","whyNot":"The database doesn't filter by version; the application uses the version to decide how to query each document."}],"answer":"a","explanation":"The Schema Versioning pattern keeps old documents in their original shape and adds a schemaVersion field so the application knows how to query each document.","concept":"The Schema Versioning pattern keeps old documents in their original shape and adds a schemaVersion field so the application knows how to query each document.","rev":1,"kind":"scenario","takeaways":["Versioning avoids costly migrations: the app reads each document by its version instead of rewriting history."]},{"id":"mongodbadvanced-002","courseId":"mongodb-advanced","domain":"data-modeling","topic":"Single collection pattern","prompt":"Students and classes share one collection. Each document holds a links array of related _ids, and an index covers that array. How does the app fetch a class together with its enrolled students?","hint":"Look at what the index on the links array is for.","source":"https://www.mongodb.com/docs/manual/data-modeling/design-patterns/single-collection/","interaction":{"type":"single"},"options":[{"id":"a","text":"One query on the indexed links array returns the related documents, with no join step.","why":"The pattern maps relationships through indexes on the reference array, so related documents come back in a single query without join operations."},{"id":"b","text":"Each class embeds full copies of its students, so no index is needed.","whyNot":"That duplicates data; the pattern keeps one copy of each document and links them by reference."},{"id":"c","text":"MongoDB joins the two document types automatically when a links field exists.","whyNot":"The pattern avoids database join operations; the index on the reference array does the mapping."},{"id":"d","text":"The class document stores every student inside it, so writes stay small.","whyNot":"Embedding all students makes each write touch a large document; the pattern splits data into smaller parts for that reason."}],"answer":"a","explanation":"The Single Collection pattern keeps related documents in one collection, linked by reference arrays that are indexed so related documents are fetched in a single query, without joins.","concept":"The Single Collection pattern keeps related documents in one collection, linked by reference arrays that are indexed so related documents are fetched in a single query, without joins.","rev":1,"kind":"scenario","takeaways":["Index the reference array: that index is what lets one query fetch related documents from a single collection."]},{"id":"mongodbadvanced-003","courseId":"mongodb-advanced","domain":"data-modeling","topic":"Materialized path trees","prompt":"Each category document stores its own _id and one string that holds the _ids of its ancestors, as in this example. Which tree model is this?","hint":"Check how the chain of ancestors is written into each document.","source":"https://www.mongodb.com/docs/manual/applications/data-models-tree-structures/","interaction":{"type":"single"},"options":[{"id":"a","text":"Materialized Paths","why":"Each document stores the _ids of its ancestors, or its full relationship path, as a string."},{"id":"b","text":"Parent References","whyNot":"That model stores only a reference to the parent node, not the whole chain of ancestors."},{"id":"c","text":"Child References","whyNot":"That model stores references to child nodes inside the parent document."},{"id":"d","text":"Array of Ancestors","whyNot":"That model keeps the ancestors in an array rather than in a single string."}],"answer":"a","explanation":"The Materialized Paths pattern stores each node's full relationship path, as a string of ancestor _ids, in the node's own document.","concept":"The Materialized Paths pattern stores each node's full relationship path, as a string of ancestor _ids, in the node's own document.","rev":1,"kind":"scenario","code":"{\n  \"_id\": \"phones\",\n  \"path\": \",electronics,\"\n}","takeaways":["Materialized paths keep the whole ancestor chain in one string field rather than in an array or a parent link."]},{"id":"mongodbadvanced-004","courseId":"mongodb-advanced","domain":"data-modeling","topic":"Nested set trees","prompt":"A company stores its org chart with the Nested Sets pattern. Which TWO statements describe the trade-off this pattern makes?","hint":"Think about what the pattern speeds up and what it makes harder to change.","source":"https://www.mongodb.com/docs/manual/applications/data-models-tree-structures/","interaction":{"type":"multiple","tellCount":true},"options":[{"id":"a","text":"Discovering a whole subtree is optimized.","why":"The Nested Sets pattern is designed to make finding subtrees fast."},{"id":"b","text":"Restructuring the tree, such as moving a branch, becomes costlier.","why":"The pattern gives up tree mutability in return for fast subtree discovery."},{"id":"c","text":"Each node stores the full string path of its ancestors.","whyNot":"That describes Materialized Paths, a different tree model."},{"id":"d","text":"Each node keeps an array of every ancestor's _id.","whyNot":"That describes the Array of Ancestors model, not Nested Sets."}],"answer":"ab","explanation":"The Nested Sets pattern optimizes discovering subtrees at the expense of tree mutability, so changing the tree's structure becomes harder.","concept":"The Nested Sets pattern optimizes discovering subtrees at the expense of tree mutability, so changing the tree's structure becomes harder.","rev":1,"kind":"scenario","takeaways":["Nested sets trade tree mutability for fast subtree discovery, so check how often your tree changes before choosing it."]},{"id":"mongodbadvanced-005","courseId":"mongodb-advanced","domain":"data-modeling","topic":"Array of ancestors trees","prompt":"Each node in a category tree keeps a reference to its parent. It also keeps an array listing the _id of every ancestor above it. Which tree model does this describe?","hint":"Compare what each node stores about its ancestors with the other tree models.","source":"https://www.mongodb.com/docs/manual/applications/data-models-tree-structures/","interaction":{"type":"single"},"options":[{"id":"a","text":"Array of Ancestors","why":"It stores references to parent nodes together with an array that holds all of the ancestors."},{"id":"b","text":"Parent References","whyNot":"That model stores only the parent reference, without an array of every ancestor."},{"id":"c","text":"Child References","whyNot":"That model stores an array of child references in the parent, which is the opposite direction."},{"id":"d","text":"Materialized Paths","whyNot":"That model stores the ancestors as one string path, not as an array."}],"answer":"a","explanation":"The Array of Ancestors pattern stores a parent reference in each node plus an array that holds all of its ancestors.","concept":"The Array of Ancestors pattern stores a parent reference in each node plus an array that holds all of its ancestors.","rev":1,"kind":"scenario","takeaways":["Array of Ancestors keeps the parent link and the full ancestor list together in each node."]}]