> For the complete MongoDB documentation index, see www.mongodb.com/docs/llms.txt

# $in (expression operator)

## Definition

Returns a boolean indicating whether a specified value is in an array.

**Note:**

This document describes the [`$in`](https://www.mongodb.com/docs/manual/reference/operator/aggregation/in.md#mongodb-expression-exp.-in) aggregation operator. For the `$in` query operator, see [$in (query predicate operator).](https://www.mongodb.com/docs/manual/reference/operator/query/in.md)

[`$in`](https://www.mongodb.com/docs/manual/reference/operator/aggregation/in.md#mongodb-expression-exp.-in) has the following [operator expression syntax:](https://www.mongodb.com/docs/manual/reference/mql/expressions.md#std-label-agg-quick-ref-operator-expressions)

```javascript
{ $in: [ <expression>, <array expression> ] }
```

| Operand | Description |
| --- | --- |
| `<expression>` | Any valid expression [expression.](https://www.mongodb.com/docs/manual/reference/mql/expressions.md#std-label-aggregation-expressions) |
| `<array expression>` | Any valid [expression](https://www.mongodb.com/docs/manual/reference/mql/expressions.md#std-label-aggregation-expressions) that resolves to an array. |

Unlike the [`$in`](https://www.mongodb.com/docs/manual/reference/operator/query/in.md#mongodb-query-op.-in) query operator, the aggregation [`$in`](https://www.mongodb.com/docs/manual/reference/operator/aggregation/in.md#mongodb-expression-exp.-in) operator does not support matching by [regular expressions.](https://www.mongodb.com/docs/manual/reference/operator/query/in.md#std-label-query-in-regex)

| Example | Results |
| --- | --- |
| `{ $in: [ 2, [ 1, 2, 3 ] ] }` | `true` |
| `{ $in: [ "abc", [ "xyz", "abc" ] ] }` | `true` |
| `{ $in: [ "xy", [ "xyz", "abc" ] ] }` | `false` |
| `{ $in: [ [ "a" ], [ "a" ] ] }` | `false` |
| `{ $in: [ [ "a" ], [ [ "a" ] ] ] }` | `true` |
| `{ $in: [ /^a/, [ "a" ] ] }` | `false` |
| `{ $in: [ /^a/, [ /^a/ ] ] }` | `true` |

## Behavior

[`$in`](https://www.mongodb.com/docs/manual/reference/operator/aggregation/in.md#mongodb-expression-exp.-in) fails with an error in either of the following cases: if the $in expression is not given exactly two arguments, or if the second argument does not resolve to an array.

## Example

The following example uses the `movies` collection from the [sample\_mflix sample dataset](https://www.mongodb.com/docs/manual/sample-data/sample-mflix.md#std-label-sample-mflix).  For details on how to load this dataset into your deployment, see [Load the sample dataset.](https://www.mongodb.com/docs/manual/sample-data/load-sample-data-local.md#std-label-sample-dataset-local)

This aggregation operation looks at the `genres` array in each movie and determines whether the string `"Drama"` is present:

```javascript
db.movies.aggregate( [
   { $match: { runtime: { $gt: 1000 } } },
   {
      $project:
        {
          _id: 0,
          title: 1,
          hasDrama: { $in: [ "Drama", "$genres" ] }
        }
   }
] )

```

**Output:**

```javascript
[
  {
    title: 'Centennial',
    hasDrama: true
  },
  {
    title: 'Baseball',
    hasDrama: false
  }
]

```
