$[identifier]

Reference type:Cheat sheetFormat:Syntax + example + use case

Reference group: Array update operators

What it does

Updates elements matching the named array filter.

Syntax

array.$[identifier].field + arrayFilters

Use case

Precisely target nested array elements.

Important notes

Array-filter identifiers start with a lowercase letter and contain alphanumeric characters.

$[identifier]: practical example
db.orders.updateOne({ _id: orderId }, { $set: { "items.$[it].checked": true } }, { arrayFilters: [{ "it.quantity": { $gt: 0 } }] })
💡 Explanation Updates elements matching the named array filter. When to use it Precisely target nested array elements. Caution Array-filter identifiers start with a lowercase letter and contain alphanumeric characters.
Key Takeaways
  • Updates elements matching the named array filter.
  • Typical use: Precisely target nested array elements.