Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to insert a document into the 'users' collection.
MongoDB
db.users.insertOne({ name: "Alice", age: [1] }) Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Putting numbers inside quotes makes them strings.
Using undefined variables instead of values.
✗ Incorrect
The age should be a number, so 25 without quotes is correct.
2fill in blank
mediumComplete the code to find all documents where the age is greater than 30.
MongoDB
db.users.find({ age: { [1]: 30 } }) Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using
$lt which means 'less than'.Using
$eq which means 'equal to'.✗ Incorrect
The operator $gt means 'greater than'.
3fill in blank
hardFix the error in the update command to set the user's city to 'Paris'.
MongoDB
db.users.updateOne({ name: "Bob" }, { [1]: { city: "Paris" } }) Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Leaving out the dollar sign.
Using incorrect operator names.
✗ Incorrect
The correct MongoDB operator to update fields is $set.
4fill in blank
hardFill both blanks to create a schema design that embeds an address inside a user document.
MongoDB
db.users.insertOne({ name: "Eve", address: { [1]: "123 Main St", [2]: "NY" } }) Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using unrelated fields like age or country here.
Mixing up field names.
✗ Incorrect
Embedding address fields like street and city inside the user document is a common schema design.
5fill in blank
hardFill all three blanks to write a query that finds users older than 20 living in 'London'.
MongoDB
db.users.find({ [1]: { [2]: 20 }, address: { [3]: "London" } }) Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong field names.
Using wrong operators.
✗ Incorrect
The query filters users where age is greater than 20 and city is 'London'.