User profiles are stored as JSON. The application must fetch a profile by user ID, but it must also find profiles by email address and list every user in a given city. A developer proposes a key-value store. Why is a document database the better fit?
Select an answer to reveal the explanation.
Short Explanation
A key-value store is a locker: you need the locker number to get anything out. A document database lets you search inside the lockers, by email, by city, by whatever field you indexed. The trap is the "opaque value" answer, which describes the key-value store's limitation, not the document store's strength.
Full Explanation
Both key-value stores and document databases can hold a JSON profile, but they differ in how much the engine understands about that value. A key-value store treats the value as opaque: it can return the profile for a given user ID very quickly, but searching by email or city would mean scanning every value in application code or maintaining hand-built secondary lookups. A document database parses the document's structure, so it can create secondary indexes on fields such as email and address.city and answer filters on them directly, while still fetching by ID efficiently. Automatic foreign key enforcement between collections is a relational feature; document databases generally leave cross-document references to the application, so it is not a reason to prefer one here. Storing each profile as an opaque value retrievable only by key is precisely the key-value behavior that fails the email and city requirements, so it argues against the proposal rather than for the alternative. Claims of strict ACID transactions across every node by default are not a defining trait of document databases, and the stem's need is query flexibility, not distributed transactions. Exam caveat: if the only access path were by user ID, the simpler key-value store would be the better fit. Operational check: create indexes on email and city, run both lookups, and confirm the query plan uses the indexes rather than a full scan.