0
0
MongoDBquery~10 mins

$inc operator for incrementing 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 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'
A$set
B$inc
C$push
D$addToSet
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.
2fill in blank
medium

Complete 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'
A$inc
B$min
C$mul
D$set
Attempts:
3 left
💡 Hint
Common Mistakes
Using $set will overwrite the value instead of incrementing.
Using $mul multiplies the value, not increments.
3fill in blank
hard

Fix 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'
A'3'
B-3
C3
Dtrue
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.
4fill in blank
hard

Fill 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'
A$inc
B$set
Cscore
D$mul
Attempts:
3 left
💡 Hint
Common Mistakes
Using $set will overwrite values instead of incrementing.
Using $mul multiplies values, not increments.
5fill in blank
hard

Fill 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'
A$set
B$inc
C1
D5
Attempts:
3 left
💡 Hint
Common Mistakes
Using $set will overwrite values instead of incrementing.
Putting numbers in quotes makes them strings, which is invalid.