$mod

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

Reference group: Query filter operators

What it does

Matches numeric values with a given remainder.

Syntax

{ field: { $mod: [divisor, remainder] } }

Use case

Select even/odd counters.

$mod: practical example
db.jobs.find({ attempt: { $mod: [2, 0] } })
💡 Explanation Matches numeric values with a given remainder. When to use it Select even/odd counters.
Key Takeaways
  • Matches numeric values with a given remainder.
  • Typical use: Select even/odd counters.