$where

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

Reference group: Query filter operators

What it does

Runs server-side JavaScript predicate logic in supported configurations.

Syntax

{$where: JavaScript expression}

Use case

Legacy diagnostics only.

Important notes

Usually avoid; can be slow or restricted. Prefer $expr.

$where: practical example
db.legacy.find({ $where: "this.a > this.b" })
💡 Explanation Runs server-side JavaScript predicate logic in supported configurations. When to use it Legacy diagnostics only. Caution Usually avoid; can be slow or restricted. Prefer $expr.
Key Takeaways
  • Runs server-side JavaScript predicate logic in supported configurations.
  • Typical use: Legacy diagnostics only.