[{"id":"mongodbbeginner-001","courseId":"mongodb-beginner","domain":"data-modeling","topic":"Embedded documents","prompt":"Your app shows each contact with its postal address on one screen. You store the address as an embedded document inside the contact. What does this let the app do?","hint":"Think about how many reads it takes to get related pieces of data together.","source":"https://www.mongodb.com/docs/manual/data-modeling/embedding/","interaction":{"type":"single"},"options":[{"id":"a","text":"Fetch the contact and its address in a single database operation","why":"Embedded documents keep related data in one document structure, so one read returns both."},{"id":"b","text":"Fetch the address only through a $lookup stage","whyNot":"$lookup joins separate collections; embedding the address removes the need for that join."},{"id":"c","text":"Store the address in its own collection automatically","whyNot":"Embedding keeps the address inside the contact document; MongoDB does not move it to another collection."},{"id":"d","text":"Skip the 16 MiB document size limit for the address","whyNot":"Embedded data still counts toward the size limit of the whole document."}],"answer":"a","explanation":"Embedded documents store related data in a single document structure, so an application can retrieve it in a single database operation.","concept":"Embedded documents store related data in a single document structure, so an application can retrieve it in a single database operation.","rev":1,"kind":"scenario","takeaways":["Embedding lets one read return related data together."]},{"id":"mongodbbeginner-002","courseId":"mongodb-beginner","domain":"data-modeling","topic":"References between documents","prompt":"Your app often looks up users on their own, not only through their orders. Each order should relate to its user without copying the user's details. Which design fits?","hint":"Think about when the related data is queried by itself, and whether copying it is a problem.","source":"https://www.mongodb.com/docs/manual/data-modeling/referencing/","interaction":{"type":"single"},"options":[{"id":"a","text":"A reference: store the user's _id in each order","why":"A reference is a link from one document to another, so users stay in their own collection and can be queried alone."},{"id":"b","text":"A full copy of the user inside every order","whyNot":"Copying the user into each order duplicates data, which is a poor fit when users are queried on their own."},{"id":"c","text":"No link: match orders to users by name at read time","whyNot":"A stored link such as an _id value is what a reference is; matching by name is not one."},{"id":"d","text":"A capped collection that holds the users","whyNot":"A capped collection has a fixed size; it does not link documents to each other."}],"answer":"a","explanation":"References store links between documents in separate collections. Use them when the related entity is often queried on its own or copying it would duplicate data.","concept":"References store links between documents in separate collections. Use them when the related entity is often queried on its own or copying it would duplicate data.","rev":1,"kind":"scenario","takeaways":["Use a reference when the related entity is queried on its own."]},{"id":"mongodbbeginner-003","courseId":"mongodb-beginner","domain":"data-modeling","topic":"The _id field","prompt":"You run the insert below into a new collection. The document has no _id field. What happens to it?","hint":"Think about who fills in the primary key when you leave it out.","source":"https://www.mongodb.com/docs/manual/core/document/#the-_id-field","interaction":{"type":"single"},"options":[{"id":"a","text":"The driver adds an _id field with a generated ObjectId","why":"If an inserted document omits _id, the MongoDB driver automatically generates an ObjectId for it."},{"id":"b","text":"The insert fails because _id is required in the input","whyNot":"The insert succeeds; the _id value is filled in automatically."},{"id":"c","text":"The document is stored with _id set to null","whyNot":"Null is not used as a default _id; a unique ObjectId is generated instead."},{"id":"d","text":"The document is stored with _id copied from the name field","whyNot":"MongoDB does not copy another field into _id; it generates an ObjectId."}],"answer":"a","explanation":"Every document in a standard collection needs a unique _id. If an inserted document omits it, the driver automatically generates an ObjectId for the _id field.","concept":"Every document in a standard collection needs a unique _id. If an inserted document omits it, the driver automatically generates an ObjectId for the _id field.","rev":1,"kind":"scenario","code":"db.people.insertOne({ name: \"Ada\" })","takeaways":["Leave _id out and the driver generates an ObjectId for you."]},{"id":"mongodbbeginner-004","courseId":"mongodb-beginner","domain":"data-modeling","topic":"Field name rules","prompt":"Which TWO statements about field names in a MongoDB document are true?","hint":"Look at the rules about which characters and repeated names are allowed.","source":"https://www.mongodb.com/docs/manual/core/document/#field-names","interaction":{"type":"multiple","tellCount":true},"options":[{"id":"a","text":"A field name cannot contain the null character","why":"The docs list the null character among the things a field name cannot contain."},{"id":"b","text":"Two fields in one document may share a name if their values differ","whyNot":"Duplicate field names are not supported and can make CRUD operations behave unexpectedly."},{"id":"c","text":"The server refuses to store any field name that contains a dot","whyNot":"The server permits storage of field names with dots and dollar signs; they are not forbidden."},{"id":"d","text":"Each field name must be unique within the document","why":"Duplicate fields are not supported, so every field name in a document must be different."}],"answer":"ad","explanation":"Field names cannot contain the null character, and each field name must be unique within a document. The server does permit dots and dollar signs in names.","concept":"Field names cannot contain the null character, and each field name must be unique within a document. The server does permit dots and dollar signs in names.","rev":1,"kind":"scenario","takeaways":["Field names are unique per document and cannot contain the null character."]},{"id":"mongodbbeginner-005","courseId":"mongodb-beginner","domain":"data-modeling","topic":"16 MB document size limit","prompt":"Your team wants to store a 30 MB video in one field of a document. Which approach fits MongoDB's document size limit?","hint":"Think about how large a single document is allowed to grow.","source":"https://www.mongodb.com/docs/manual/reference/limits/","interaction":{"type":"single"},"options":[{"id":"a","text":"Store the file with the GridFS API, which is built for large files","why":"Documents must stay under 16 MiB; GridFS is the API MongoDB provides for data larger than that."},{"id":"b","text":"Store it as one long string field, since strings have no size limit","whyNot":"The whole document, string fields included, must be smaller than 16 MiB."},{"id":"c","text":"Store it as a Decimal128 value to shrink its size","whyNot":"Decimal128 is for precise decimal numbers, not for compressing binary files."},{"id":"d","text":"Nest it deeper, with one object inside another","whyNot":"Nesting adds levels, not room; the 16 MiB limit still applies to the whole document."}],"answer":"a","explanation":"BSON documents must be smaller than 16 mebibytes. For larger binary data, MongoDB provides the GridFS API.","concept":"BSON documents must be smaller than 16 mebibytes. For larger binary data, MongoDB provides the GridFS API.","rev":1,"kind":"scenario","takeaways":["Documents must stay under 16 MiB; use GridFS for larger binary data."]}]