0
0
MongoDBquery~20 mins

Why document databases over relational in MongoDB - Challenge Your Understanding

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Document Database Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
Advantages of Document Databases for Flexible Data

Which of the following is a key reason to choose a document database over a relational database?

ADocument databases require fixed schemas for all documents.
BRelational databases automatically scale horizontally without extra setup.
CDocument databases allow storing data with varying structures easily in one collection.
DRelational databases store data as JSON documents natively.
Attempts:
2 left
💡 Hint

Think about how data structure flexibility affects storing different types of records.

query_result
intermediate
2:00remaining
Query Result: Embedded Documents in MongoDB

Given a MongoDB collection users where each document has an embedded address object, what will this query return?

db.users.find({"address.city": "Seattle"})
AAll user documents where the city in the address is Seattle.
BAll users regardless of city because the query is invalid.
CAn error because embedded fields cannot be queried.
DOnly the address subdocuments with city Seattle, not the whole user documents.
Attempts:
2 left
💡 Hint

Think about how MongoDB queries nested fields inside documents.

📝 Syntax
advanced
2:00remaining
Correct MongoDB Insert Syntax for Nested Document

Which option correctly inserts a document with a nested profile object into a MongoDB collection members?

MongoDB
db.members.insertOne({name: "Alice", profile: {age: 30, city: "Boston"}})
Adb.members.insertOne({name: "Alice", profile: {age: 30, city: "Boston"}})
Bdb.members.insertOne({name: "Alice", profile: "age: 30, city: Boston"})
Cdb.members.insertOne({name: "Alice", profile: (age: 30, city: "Boston")})
Ddb.members.insertOne({name: "Alice", profile: [age: 30, city: "Boston"]})
Attempts:
2 left
💡 Hint

Remember the syntax for nested objects in JSON-like documents.

optimization
advanced
2:00remaining
Optimizing Queries with Indexes in Document Databases

You have a MongoDB collection with millions of documents. You often query by the field email. Which option best improves query speed?

AUse a text search index on all fields.
BCreate an index on the <code>email</code> field.
CStore emails in a separate collection and join on query.
DAdd a unique constraint on the <code>email</code> field but no index.
Attempts:
2 left
💡 Hint

Think about how databases speed up lookups on specific fields.

🔧 Debug
expert
3:00remaining
Why Does This MongoDB Update Not Change the Document?

Given this update command, why does the document remain unchanged?

db.products.updateOne({name: "Pen"}, {price: 1.5})
AThe collection name <code>products</code> is reserved and cannot be updated.
BThe query filter is incorrect and matches no documents.
CMongoDB does not allow updating numeric fields directly.
DThe update document is missing an update operator like <code>$set</code>.
Attempts:
2 left
💡 Hint

Think about how MongoDB expects update commands to be structured.