Skip to main content
The $must operator requires all specified conditions to match. Documents are only included in results if they satisfy every condition within the $must clause. This implements logical AND behavior. When you specify multiple field conditions at the top level of a query without any boolean operator, they are implicitly wrapped in a $must. These queries are equivalent:
// Implicit must
{ name: "headphones", inStock: true }

// Explicit $must
{ $must: { name: "headphones", inStock: true } }

Syntax Options

The $must operator accepts either an object or an array:
  • Object syntax: Each key-value pair is a condition that must match
  • Array syntax: Each element is a separate condition object that must match
Array syntax is useful when you have multiple conditions on the same field or when building queries programmatically.

Examples

// Explicit $must
await products.query({
  filter: {
    $must: [{ name: "headphones" }, { inStock: true }],
  },
});

// Equivalent implicit form
await products.query({
  filter: {
    name: "headphones",
    inStock: true,
  },
});

// $must with object syntax
await products.query({
  filter: {
    $must: {
      name: "headphones",
      inStock: true,
    },
  },
});