0
0
MongoDBquery~10 mins

Why advanced updates matter 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 named 'Alice' to 30.

MongoDB
db.users.updateOne({name: 'Alice'}, {$set: {age: [1])
Drag options to blanks, or click blank then click option'
A25
B30
C35
D40
Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong age value.
Forgetting to use $set operator.
2fill in blank
medium

Complete the code to increment the score of a player named 'Bob' by 10.

MongoDB
db.players.updateOne({name: 'Bob'}, {$inc: {score: [1])
Drag options to blanks, or click blank then click option'
A5
B20
C10
D15
Attempts:
3 left
💡 Hint
Common Mistakes
Using $set instead of $inc.
Using wrong increment value.
3fill in blank
hard

Fix the error in the update code to add a new tag 'urgent' to the tags array for task with id 123.

MongoDB
db.tasks.updateOne({_id: 123}, {$push: {tags: [1])
Drag options to blanks, or click blank then click option'
A'urgent'
Burgent
C{urgent}
D[urgent]
Attempts:
3 left
💡 Hint
Common Mistakes
Not quoting the string value.
Using curly braces or brackets incorrectly.
4fill in blank
hard

Fill both blanks to update the price to 19.99 and set the status to 'available' for product with id 456.

MongoDB
db.products.updateOne({_id: 456}, {$set: {price: [1], status: [2])
Drag options to blanks, or click blank then click option'
A19.99
B'available'
C'sold out'
D20.99
Attempts:
3 left
💡 Hint
Common Mistakes
Quoting numbers or not quoting strings.
Using wrong values for price or status.
5fill in blank
hard

Fill all three blanks to update the user's email, increment login count by 1, and add 'premium' to roles array for user with username 'jane'.

MongoDB
db.users.updateOne({username: 'jane'}, {$set: {email: [1], $inc: {logins: [2], $push: {roles: [3])
Drag options to blanks, or click blank then click option'
A'jane@example.com'
B1
C'premium'
D'jane@domain.com'
Attempts:
3 left
💡 Hint
Common Mistakes
Not quoting strings, wrong increment value, or wrong email.