{ _id: 1, tags: ["red", "blue", "green", "blue"] }, what will be the tags array after applying {$pull: {tags: "blue"}}?db.collection.updateOne({_id: 1}, {$pull: {tags: "blue"}})
db.collection.findOne({_id: 1})The $pull operator removes all elements equal to the specified value from the array. Here, all "blue" values are removed, leaving only "red" and "green".
{ _id: 2, items: [{id: 1, qty: 5}, {id: 2, qty: 10}, {id: 3, qty: 3}] }. What will be the items array after applying {$pull: {items: {qty: {$lt: 5}}}}?db.collection.updateOne({_id: 2}, {$pull: {items: {qty: {$lt: 5}}}})
db.collection.findOne({_id: 2})The $pull operator removes all array elements matching the condition {qty: {$lt: 5}}. Only the object with qty: 3 matches (3 < 5), so it is removed. The objects with qty: 5 and qty: 10 remain.
numbers?db.collection.updateOne({_id: 3}, {$pull: {numbers: 5}})Option B contains a syntax error because it uses ne: 5 without the required $ prefix. Query operators in MongoDB must start with $ (e.g., $ne). Options A, B, and D are syntactically valid.
{ _id: 4, scores: [10, 20, 30, 40, 50] }, what will be the scores array after applying {$pull: {scores: {$gte: 20, $lte: 40}}}?db.collection.updateOne({_id: 4}, {$pull: {scores: {$gte: 20, $lte: 40}}})
db.collection.findOne({_id: 4})The $pull operator removes all elements where the value is greater than or equal to 20 and less than or equal to 40. So 20, 30, and 40 are removed, leaving 10 and 50.
{$pull: {items: {status: "active"}}} on a document where items is an array of strings like ["active", "inactive", "active"]. Why does $pull not remove any elements?The $pull operator removes elements matching the condition. Here, the condition is an object {status: "active"}, but the array contains strings, not objects. So no elements match the condition, and nothing is removed.