Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to update one document in the collection.
MongoDB
db.collection.updateOne({ name: "John" }, { [1]: { age: 30 } }) Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using $push instead of $set will try to add to an array, not update a field.
Using $inc will increment a number, not set it to a specific value.
✗ Incorrect
The $set operator updates the value of a field in the matched document.
2fill in blank
mediumComplete the code to update the first document where age is 25.
MongoDB
db.users.updateOne({ age: [1] }, { $set: { status: "active" } }) Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a string "25" instead of number 25 causes no match.
Using true or null does not match the age field.
✗ Incorrect
The query filter should match the number 25, not the string "25".
3fill in blank
hardFix the error in the updateOne call to increment the score by 5.
MongoDB
db.scores.updateOne({ player: "Alice" }, { [1]: { score: 5 } }) Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using $set replaces the score instead of incrementing it.
Using $push is for arrays, not numbers.
✗ Incorrect
The $inc operator increments a numeric field by the given value.
4fill in blank
hardFill both blanks to update the city and add a new field country.
MongoDB
db.customers.updateOne({ name: "Bob" }, { [1]: { city: "Paris" }, [2]: { country: "France" } }) Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using $inc or $unset will not add or update string fields.
Using different operators for each field is incorrect here.
✗ Incorrect
Use $set to update or add fields in the document.
5fill in blank
hardFill all three blanks to update the user's email, increment login count, and remove the temp field.
MongoDB
db.users.updateOne({ username: "jane" }, { [1]: { email: "jane@example.com" }, [2]: { logins: 1 }, [3]: { temp: "" } }) Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using $push instead of $inc for numbers.
Using $set to remove fields instead of $unset.
Not passing the field name as a string to $unset.
✗ Incorrect
$set updates the email, $inc increments the login count, and $unset removes the temp field.