0
0
MongoDBquery~10 mins

updateOne method in MongoDB - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete 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'
A$unset
B$set
C$inc
D$push
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.
2fill in blank
medium

Complete 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'
A"25"
Btrue
C25
Dnull
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.
3fill in blank
hard

Fix 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'
A$inc
B$set
C$push
D$mul
Attempts:
3 left
💡 Hint
Common Mistakes
Using $set replaces the score instead of incrementing it.
Using $push is for arrays, not numbers.
4fill in blank
hard

Fill 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'
A$set
B$inc
C$unset
D$push
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.
5fill in blank
hard

Fill 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'
A$set
B$inc
C$unset
D$push
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.