Challenge - 5 Problems
MongoDB with Deno Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ query_result
intermediateFind documents with a specific field value
Given a MongoDB collection named
Assume the collection has:
users with documents containing age and name fields, what will be the output of this query?const result = await users.find({ age: { $gt: 25 } }).toArray();Assume the collection has:
[{ name: "Alice", age: 30 }, { name: "Bob", age: 22 }, { name: "Carol", age: 27 }]Deno
const result = await users.find({ age: { $gt: 25 } }).toArray();
Attempts:
2 left
💡 Hint
Look for documents where age is greater than 25.
✗ Incorrect
The query filters documents where the age field is greater than 25, so only Alice (30) and Carol (27) match.
📝 Syntax
intermediateIdentify the syntax error in MongoDB update query
Which option contains a syntax error when updating a document in MongoDB using Deno?
Update the user with
Update the user with
_id: 1 to set name to "John".Deno
await users.updateOne({ _id: 1 }, { $set: { name: "John" } });
Attempts:
2 left
💡 Hint
MongoDB update operators start with a $ sign.
✗ Incorrect
Option B uses 'set' instead of '$set', which is invalid syntax for MongoDB update operators. Option C is missing braces around the $set value. Option D is missing the closing parenthesis.
❓ optimization
advancedOptimize a MongoDB query for large collections
You want to find all users with
status: "active" in a large collection. Which option will optimize the query performance best?Attempts:
2 left
💡 Hint
Using an index hint can improve query speed if an index exists.
✗ Incorrect
Option A uses a hint to force MongoDB to use the index on 'status', improving performance on large collections.
🔧 Debug
advancedDebug why a MongoDB insertOne fails
You run this code to insert a document:
But it throws an error:
await users.insertOne({ _id: 1, name: "Eve" });But it throws an error:
duplicate key error. What is the likely cause?Attempts:
2 left
💡 Hint
Duplicate key errors usually relate to unique fields like _id.
✗ Incorrect
The error means a document with _id: 1 already exists, so inserting another with the same _id fails.
🧠 Conceptual
expertUnderstanding MongoDB transactions with Deno
Which statement about MongoDB transactions in Deno is correct?
Attempts:
2 left
💡 Hint
Think about MongoDB architecture requirements for transactions.
✗ Incorrect
MongoDB supports multi-document transactions only on replica sets or sharded clusters, not standalone servers.
