Unit 3: Schema Design and Data Modeling - Practice Quiz

CSE494 — Intelligent Nosql Databases 60 Questions
0 Correct 0 Wrong 60 Left
0/60

1 What does MongoDB's schema-less nature allow?

Schema-less Nature of MongoDB Easy
A. Databases can have only one collection
B. Documents can store only text values
C. Documents in a collection can have different fields
D. Collections can contain only identical documents

2 Which data format does MongoDB use to store documents internally?

Schema-less Nature of MongoDB Easy
A. XML
B. CSV
C. YAML
D. BSON

3 In 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

4 What 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

5 What 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

6 When 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

7 Which 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

8 How 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

9 Which 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

10 How 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

11 When 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

12 Which 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

13 What 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

14 What 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

15 Why 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

16 What 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

17 In 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

18 In 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

19 What 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

20 Which 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

21 A 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

22 An 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

23 A 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

24 Thousands 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

25 A 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

26 An 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

27 A 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

28 A 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

29 A 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

30 Orders 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

31 Students 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

32 Articles 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

33 Authors 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

34 A 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

35 A 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 }

36 A 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

37 An 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

38 A 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

39 A 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" }

40 A 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

41 A 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.

42 A 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.

43 An 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.

44 A 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.

45 An 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.

46 Each 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.

47 A 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.

48 A 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.

49 A 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.

50 Support 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.

51 Students 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.

52 An 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.

53 A 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.

54 A 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}.

55 A 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.

56 An 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.

57 A 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.

58 A 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.

59 User 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.

60 A 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.