Which of the following is a key reason to choose a document database over a relational database?
Think about how data structure flexibility affects storing different types of records.
Document databases store data as flexible JSON-like documents, allowing different fields per record without schema changes. Relational databases require fixed tables and columns.
Given a MongoDB collection users where each document has an embedded address object, what will this query return?
db.users.find({"address.city": "Seattle"})Think about how MongoDB queries nested fields inside documents.
The query matches documents where the embedded field address.city equals "Seattle" and returns the whole matching documents.
Which option correctly inserts a document with a nested profile object into a MongoDB collection members?
db.members.insertOne({name: "Alice", profile: {age: 30, city: "Boston"}})Remember the syntax for nested objects in JSON-like documents.
Option A uses correct JSON object syntax for the nested profile. Options A and C use invalid brackets, and D uses a string instead of an object.
You have a MongoDB collection with millions of documents. You often query by the field email. Which option best improves query speed?
Think about how databases speed up lookups on specific fields.
Creating an index on the email field allows fast lookups. Unique constraints also create indexes, but just adding a constraint without an index is not possible. Text search indexes are for full-text search, not exact matches.
Given this update command, why does the document remain unchanged?
db.products.updateOne({name: "Pen"}, {price: 1.5})Think about how MongoDB expects update commands to be structured.
MongoDB update commands require update operators like $set to specify which fields to change. Without it, MongoDB treats the second argument as a replacement document, which must contain the full document. Here, it tries to replace the document with only {price: 1.5}, which fails silently if the filter matches.