0
0
MongoDBquery~10 mins

Why updating documents matters in MongoDB - Test Your Understanding

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

Complete the code to update the age of a user to 30.

MongoDB
db.users.updateOne({name: "Alice"}, {$set: {age: [1])
Drag options to blanks, or click blank then click option'
A25
Bage
C"30"
D30
Attempts:
3 left
💡 Hint
Common Mistakes
Using quotes around 30 makes it a string, not a number.
Using the field name instead of the value.
2fill in blank
medium

Complete the code to update all documents where status is 'pending' to have status 'complete'.

MongoDB
db.orders.updateMany({status: "pending"}, {$set: {status: [1])
Drag options to blanks, or click blank then click option'
A"complete"
B"pending"
Ccomplete
Dstatus
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting quotes around the string value.
Using the old status value instead of the new one.
3fill in blank
hard

Fix the error in the update code to increment the score by 5.

MongoDB
db.players.updateOne({name: "Bob"}, {$inc: {score: [1])
Drag options to blanks, or click blank then click option'
A5
Bscore
C-5
D"5"
Attempts:
3 left
💡 Hint
Common Mistakes
Using a string "5" instead of number 5.
Using a negative number which decreases the score.
4fill in blank
hard

Fill both blanks to update the user's city to 'Seattle' and add a new field 'verified' set to true.

MongoDB
db.users.updateOne({name: "Carol"}, {$set: {city: [1], verified: [2])
Drag options to blanks, or click blank then click option'
A"Seattle"
Btrue
Cfalse
D"Portland"
Attempts:
3 left
💡 Hint
Common Mistakes
Using false instead of true for verified.
Forgetting quotes around city name.
5fill in blank
hard

Fill all three blanks to update the product price to 19.99, increase stock by 10, and set available to true.

MongoDB
db.products.updateOne({productId: 123}, {$set: {price: [1], available: [2], $inc: {stock: [3])
Drag options to blanks, or click blank then click option'
A19.99
Btrue
C10
Dfalse
Attempts:
3 left
💡 Hint
Common Mistakes
Using false instead of true for available.
Using a string instead of number for price or stock.