$[]

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

Reference group: Array update operators

What it does

Targets every element in the specified array.

Syntax

array.$[].field

Use case

Apply a field update to all embedded items.

$[]: practical example
db.orders.updateOne({ _id: orderId }, { $set: { "items.$[].reviewed": true } })
💡 Explanation Targets every element in the specified array. When to use it Apply a field update to all embedded items.
Key Takeaways
  • Targets every element in the specified array.
  • Typical use: Apply a field update to all embedded items.