> This page location: /docs.md > /docs/development.md > /docs/manual/reference/mql.md > /docs/manual/reference/mql/expressions.md

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

# $cond (expression operator)

## Definition

Evaluates a boolean expression to return one of the two specified return expressions.

## Compatibility

You can use `$cond` for deployments hosted in the following environments:

- [MongoDB Atlas](https://www.mongodb.com/docs/atlas): The fully managed service for MongoDB deployments in the cloud

* [MongoDB Enterprise](https://www.mongodb.com/docs/manual/administration/install-enterprise.md#std-label-install-mdb-enterprise): The subscription-based, self-managed version of MongoDB

* [MongoDB Community](https://www.mongodb.com/docs/manual/administration/install-community.md#std-label-install-mdb-community-edition): The source-available, free-to-use, and self-managed version of MongoDB

## Syntax

The [`$cond`](https://www.mongodb.com/docs/manual/reference/operator/aggregation/cond.md#mongodb-expression-exp.-cond) expression has one of two syntaxes:

```javascript
{ $cond: { if: <boolean-expression>, then: <true-case>, else: <false-case> } }
```

Or:

```javascript
{ $cond: [ <boolean-expression>, <true-case>, <false-case> ] }
```

[`$cond`](https://www.mongodb.com/docs/manual/reference/operator/aggregation/cond.md#mongodb-expression-exp.-cond) requires all three arguments (`if-then-else`) for either syntax.

If the `<boolean-expression>` evaluates to `true`, then [`$cond`](https://www.mongodb.com/docs/manual/reference/operator/aggregation/cond.md#mongodb-expression-exp.-cond) evaluates and returns the value of the `<true-case>` expression. Otherwise, [`$cond`](https://www.mongodb.com/docs/manual/reference/operator/aggregation/cond.md#mongodb-expression-exp.-cond) evaluates and returns the value of the `<false-case>` expression.

The arguments can be any valid [expression.](https://www.mongodb.com/docs/manual/reference/mql/expressions.md#std-label-aggregation-expressions)

**See also:**

[`$switch`](https://www.mongodb.com/docs/manual/reference/operator/aggregation/switch.md#mongodb-expression-exp.-switch)

## Examples

The examples on this page use data from the [sample\_mflix 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 self-managed MongoDB deployment, see [Load the Sample Dataset](https://www.mongodb.com/docs/manual/sample-data/load-sample-data-local.md#std-label-sample-dataset-local). If you made any modifications to the sample databases, you may need to drop and recreate the databases to run the examples on this page.

The following aggregation operation uses the [`$cond`](https://www.mongodb.com/docs/manual/reference/operator/aggregation/cond.md#mongodb-expression-exp.-cond) expression to assign a rental price to each movie. The operation prices movies with an `imdb.rating` greater than or equal to `9` at `5.99`. The operation prices all other movies at `3.99`:

```javascript
db.movies.aggregate( [
   { $match: { runtime: { $gt: 1000 } } },
   {
      $project:
        {
          title: 1,
          rentalPrice:
            {
              $cond: {
                 if: { $gte: [ "$imdb.rating", 9 ] },
                 then: 5.99,
                 else: 3.99
              }
            }
        }
   }
] )

```

**Output:**

```javascript
[
  { _id: ..., title: 'Baseball', rentalPrice: 5.99 },
  { _id: ..., title: 'Centennial', rentalPrice: 3.99 }
]

```

The following operation uses the array syntax of the [`$cond`](https://www.mongodb.com/docs/manual/reference/operator/aggregation/cond.md#mongodb-expression-exp.-cond) expression and returns the same results:

```javascript
db.movies.aggregate( [
   { $match: { runtime: { $gt: 1000 } } },
   {
      $project:
        {
          title: 1,
          rentalPrice:
            {
              $cond: [
                 { $gte: [ "$imdb.rating", 9 ] },
                 5.99,
                 3.99
              ]
            }
        }
   }
] )

```
