Skip to content

$limit

Limits the number of documents passed to the next stage.


Syntax

{ "$limit": <positiveInteger> }

The integer caps how many documents are emitted downstream.


✅ Basic Example

📌 Stage

{
  "$limit": 2
}

📥 Input

[
  {
    "a": 1
  },
  {
    "a": 2
  },
  {
    "a": 3
  }
]

📤 Output

[
  {
    "a": 1
  },
  {
    "a": 2
  }
]

🧱 Deep Nested Pipeline Usage (Ecommerce)

[
  {
    "$match": {
      "status": "active"
    }
  },
  {
    "$limit": 1
  }
]

📥 Input Document

[
  {
    "status": "active"
  },
  {
    "status": "inactive"
  }
]

📤 Output Documents

[
  {
    "status": "active"
  }
]

➕ Supported Accumulators

None for this stage


🔧 Common Operators

None