$[identifier] (Filtered Positional)

Last updated: 2026-10-09

$[identifier] (Filtered Positional)

$[identifier] is the positional operator that, together with arrayFilters, updates only the array elements matching a condition. `{ $set: { 'grades.$[elem]': 90 } }, { arrayFilters: [{ 'elem.grade': { $gte: 85 } }] }`. The most flexible array update, introduced in MongoDB 3.6; identifiers are defined in arrayFilters and can match nested document fields.

CategoryUpdate Modifier
MongoDB Version3.6+
Example Languagemongosh (Shell)

📝 Syntax

{ <update operator>: { '<array field>.$[<identifier>]': <value> } }, { arrayFilters: [ { '<identifier>.<field>': <condition> } ] }

⚙️ Parameters

array fieldThe array field to update.
identifierA placeholder defined in arrayFilters, e.g. elem.
arrayFiltersThe condition array defining identifier matching rules.

Returns:The update result

▶ Example

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

// $[elem]: update only grades >= 85
// arrayFilters defines the elem rule
db.students.updateOne(
  { _id: 1 },
  { $set: { 'grades.$[elem]': 100 } },
  { arrayFilters: [{ 'elem': { $gte: 85 } }] }
)

Output:

// Only grades of 85 or higher become 100; the rest stay unchanged

📌 Notes

More hands-on cases coming soon.

📚 Related Tutorials

❓ FAQ

QWhat is the difference between $[elem] and $[]?
A$[] updates all elements; $[elem] with arrayFilters updates only matching ones.
QHow do I write arrayFilters?
A{ arrayFilters: [{ 'elem': { $gte: 85 } }] }; identifiers have no $ prefix.
QCan I filter on nested fields?
AYes, e.g. { 'elem.type': 'exam' }.
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%

🙏 帮我们做得更好

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

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