$pull (Remove Matching Elements)

Last updated: 2026-10-09

$pull (Remove Matching Elements)

$pull removes from an array every element that equals a value or satisfies a condition. `{ $pull: { tags: 'spam' } }` removes all 'spam'; `{ $pull: { scores: { $lt: 60 } } }` removes every score below 60. It removes all matches, not just one — the standard tool for cleaning arrays.

CategoryUpdate Array
MongoDB Version1.0+
Example Languagemongosh (Shell)

📝 Syntax

{ $pull: { <array field>: <value> | <condition> } }

⚙️ Parameters

array fieldThe array field to clean.
value or conditionAn equality value or query condition, e.g. 'spam' or { $lt: 60 }.

Returns:The update result

▶ Example

Run the commands below in your local mongosh (requires a running mongod):

// $pull: remove all spam tags
db.articles.updateOne(
  { _id: 1 },
  { $pull: { tags: 'spam' } }
)

// Remove scores below 60
db.students.updateOne(
  { _id: 1 },
  { $pull: { scores: { $lt: 60 } } }
)

Output:

// All spam tags and all scores below 60 are removed

📌 Notes

📚 Related Tutorials

❓ FAQ

QWhat is the difference between $pull and $pop?
A$pull removes by value or condition anywhere; $pop removes only the first or last.
QCan $pull remove by condition?
AYes, conditions support query operators, e.g. { $pull: { scores: { $lt: 60 } } }.
QDoes $pull remove all matches or just one?
AAll matching elements are removed.
Web-Tutorial.com

Web-Tutorial Tech Team

A team of developers maintaining programming tutorials. Each tutorial is written and reviewed by developers with expertise in that field. We work to keep our content accurate and reliable — if you spot an issue, please let us know.

100%

🙏 帮我们做得更好

我们是刚上线的编程教程站,几个人的小团队,精力有限。页面虽经检查,难免还有疏漏——链接失效、排版错乱、内容有误、语言生硬……

如果您发现了,麻烦告诉我们,我们会在收到反馈后第一时间进行修复,再次感谢您的光临 🙏