0
0
MongoDBquery~10 mins

$pull operator for removing from arrays 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 remove all elements equal to 5 from the 'scores' array.

MongoDB
db.students.updateOne({name: 'Alice'}, {$pull: {scores: [1])
Drag options to blanks, or click blank then click option'
A"5"
B5
C{ $eq: 5 }
D[5]
Attempts:
3 left
💡 Hint
Common Mistakes
Using quotes around numbers removes strings, not numbers.
Passing an array instead of a value causes errors.
2fill in blank
medium

Complete the code to remove all elements greater than 10 from the 'grades' array.

MongoDB
db.courses.updateMany({}, {$pull: {grades: { [1]: 10 }}})
Drag options to blanks, or click blank then click option'
A$eq
B$lt
C$gt
D$ne
Attempts:
3 left
💡 Hint
Common Mistakes
Using $lt removes elements less than 10, which is wrong here.
Using $eq removes only elements equal to 10.
3fill in blank
hard

Fix the error in the code to remove all elements less than or equal to 3 from the 'values' array.

MongoDB
db.data.updateOne({}, {$pull: {values: { [1]: 3 }}})
Drag options to blanks, or click blank then click option'
A$gte
B$eq
C$lt
D$lte
Attempts:
3 left
💡 Hint
Common Mistakes
Using $lt excludes elements equal to 3.
Using $gte removes elements greater than or equal to 3, which is opposite.
4fill in blank
hard

Fill both blanks to remove all elements that are strings equal to 'remove' from the 'tags' array.

MongoDB
db.collection.updateMany({}, {$pull: {tags: { [1]: [2] }}})
Drag options to blanks, or click blank then click option'
A$eq
B"remove"
C'remove'
D$ne
Attempts:
3 left
💡 Hint
Common Mistakes
Using $ne removes elements not equal to the value, which is wrong.
Using single quotes may cause syntax issues in some environments.
5fill in blank
hard

Fill both blanks to remove all elements from the 'items' array where the 'price' field is less than 20.

MongoDB
db.store.updateOne({id: 1}, {$pull: {items: { [1]: { [2]: 20 }}}})
Drag options to blanks, or click blank then click option'
Aprice
B$lt
Dcost
Attempts:
3 left
💡 Hint
Common Mistakes
Using cost instead of price as field name.
Using $gt instead of $lt operator.