Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to increment the field 'score' by 1 in a MongoDB update.
MongoDB
db.collection.updateOne({ _id: 1 }, { [1]: { score: 1 } }) Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using $set instead of $inc will replace the value instead of incrementing.
Using $push or $addToSet are for arrays, not numbers.
✗ Incorrect
The $inc operator increments the value of a field by the specified amount.
2fill in blank
mediumComplete the code to increment the 'views' field by 5 in a MongoDB update.
MongoDB
db.collection.updateOne({ _id: 2 }, { [1]: { views: 5 } }) Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using $set will overwrite the value instead of incrementing.
Using $mul multiplies the value, not increments.
✗ Incorrect
$inc adds the specified number to the current value of the field.
3fill in blank
hardFix the error in the update code to increment 'likes' by 3.
MongoDB
db.collection.updateOne({ _id: 3 }, { $inc: { likes: [1] } }) Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Putting the number in quotes makes it a string, which is invalid.
Using true is not a number and causes an error.
✗ Incorrect
The increment value must be a number, not a string or boolean.
4fill in blank
hardFill both blanks to increment 'count' by 2 and 'score' by 10 in one update.
MongoDB
db.collection.updateOne({ _id: 4 }, { [1]: { count: 2, [2]: 10 } }) Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using $set will overwrite values instead of incrementing.
Using $mul multiplies values, not increments.
✗ Incorrect
Use $inc to increment fields. The second blank is the field name 'score'.
5fill in blank
hardFill all three blanks to increment 'likes' by 1, 'views' by 5, and 'shares' by 2 in one update.
MongoDB
db.collection.updateOne({ _id: 5 }, { [1]: { likes: [2], views: [3], shares: 2 } }) Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using $set will overwrite values instead of incrementing.
Putting numbers in quotes makes them strings, which is invalid.
✗ Incorrect
Use $inc to increment fields. The values 1 and 5 are the amounts to add to 'likes' and 'views'.