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

# $radiansToDegrees (expression operator)

## Definition

Converts an input value measured in radians to degrees.

[`$radiansToDegrees`](https://www.mongodb.com/docs/manual/reference/operator/aggregation/radianstodegrees.md#mongodb-expression-exp.-radiansToDegrees) has the following syntax:

```javascript
{ $radiansToDegrees: <expression> }
```

[`$radiansToDegrees`](https://www.mongodb.com/docs/manual/reference/operator/aggregation/radianstodegrees.md#mongodb-expression-exp.-radiansToDegrees) takes any valid [expression](https://www.mongodb.com/docs/manual/reference/mql/expressions.md#std-label-aggregation-expressions) that resolves to a number.

By default [`$radiansToDegrees`](https://www.mongodb.com/docs/manual/reference/operator/aggregation/radianstodegrees.md#mongodb-expression-exp.-radiansToDegrees) returns values as a `double`. [`$radiansToDegrees`](https://www.mongodb.com/docs/manual/reference/operator/aggregation/radianstodegrees.md#mongodb-expression-exp.-radiansToDegrees) can also return values as a [128-bit decimal](https://www.mongodb.com/docs/mongodb-shell/reference/data-types.md#std-label-shell-type-decimal) as long as the `<expression>` resolves to a 128-bit decimal value.

For more information on expressions, see [Expressions.](https://www.mongodb.com/docs/manual/reference/mql/expressions.md#std-label-aggregation-expressions)

## Behavior

### `null`, `NaN`, and `+/- Infinity`

If the argument resolves to a value of `null` or refers to a field that is missing, [`$radiansToDegrees`](https://www.mongodb.com/docs/manual/reference/operator/aggregation/radianstodegrees.md#mongodb-expression-exp.-radiansToDegrees) returns `null`. If the argument resolves to `NaN`, [`$radiansToDegrees`](https://www.mongodb.com/docs/manual/reference/operator/aggregation/radianstodegrees.md#mongodb-expression-exp.-radiansToDegrees) returns `NaN`. If the argument resolves to negative or positive infinity, [`$radiansToDegrees`](https://www.mongodb.com/docs/manual/reference/operator/aggregation/radianstodegrees.md#mongodb-expression-exp.-radiansToDegrees) negative or positive infinity respectively.

| Example | Results |
| --- | --- |
| `{ $radiansToDegrees: NaN }` | `NaN` |
| `{ $radiansToDegrees: null }` | `null` |
| `{ $radiansToDegrees : Infinity}` | `Infinity` |
| `{ $radiansToDegrees : -Infinity }` | `-Infinity` |

## Example

The `trigonometry` collection contains a document that contains three angles measured in radians:

```json
{
  "angle_a" : Decimal128("0.9272952180016122324285124629224290"),
  "angle_b" : Decimal128("0.6435011087932843868028092287173227"),
  "angle_c" : Decimal128("1.570796326794896619231321691639752")
}
```

The following aggregation operation uses the [`$radiansToDegrees`](https://www.mongodb.com/docs/manual/reference/operator/aggregation/radianstodegrees.md#mongodb-expression-exp.-radiansToDegrees) expression to convert each value to its degree equivalent and add them to the input document using the [`$addFields`](https://www.mongodb.com/docs/manual/reference/operator/aggregation/addfields.md#mongodb-pipeline-pipe.-addFields) pipeline stage.

```bash
db.trigangles.aggregate([
  {
    $addFields: {
      "angle_a_deg" : { $radiansToDegrees : "$angle_a"},
      "angle_b_deg" : { $radiansToDegrees : "$angle_b"},
      "angle_c_deg" : { $radiansToDegrees : "$angle_c"}
    }
  }
])
```

The operation returns the following document:

```bash
{
  "_id" : ObjectId("5c50aec71c75c59232b3ede4"),
  "angle_a" : Decimal128("0.9272952180016122324285124629224290"),
  "angle_b" : Decimal128("0.6435011087932843868028092287173227"),
  "angle_c" : Decimal128("1.570796326794896619231321691639752"),
  "angle_a_deg" : Decimal128("53.13010235415597870314438744090659"),
  "angle_b_deg" : Decimal128("36.86989764584402129685561255909341"),
  "angle_c_deg" : Decimal128("90.00000000000000000000000000000000")
}
```

Since `angle_a`, `angle_b`, and `angle_c` are stored as [128-bit decimals](https://www.mongodb.com/docs/mongodb-shell/reference/data-types.md#std-label-shell-type-decimal), the output of [`$radiansToDegrees`](https://www.mongodb.com/docs/manual/reference/operator/aggregation/radianstodegrees.md#mongodb-expression-exp.-radiansToDegrees) is a 128-bit decimal.
