- Reference >
- Operators >
- Aggregation Pipeline Operators >
- $degreesToRadians (aggregation)
$degreesToRadians (aggregation)¶
On this page
Definition¶
-
$degreesToRadians
¶ New in version 4.2.
Converts an input value measured in degrees to radians.
$degreesToRadians
has the following syntax:$degreesToRadians
takes any valid expression that resolves to a number.By default
$degreesToRadians
returns values as adouble
.$degreesToRadians
can also return values as a 128-bit decimal as long as the<expression>
resolves to a 128-bit decimal value.For more information on expressions, see Expressions.
Behavior¶
null
, NaN
, and +/- Infinity
¶
If the argument resolves to a value of null
or refers to a field
that is missing, $degreesToRadians
returns null
. If
the argument resolves to NaN
, $degreesToRadians
returns NaN
. If the argument resolves to negative or positive
infinity, $degreesToRadians
negative or positive infinity
respectively.
Example | Results |
---|---|
{ $degreesToRadians: NaN } |
NaN |
{ $degreesToRadians: null } |
null |
{ $degreesToRadians : Infinity} |
Infinity |
{ $degreesToRadians : -Infinity } |
-Infinity |
Example¶
The trigonometry
collection contains a document that contains
three angles measured in degrees:
The following aggregation operation uses the
$degreesToRadians
expression to convert each value to
its radian equivalent and add them to the input document using the
$addFields
pipeline stage.
The operation returns the following document:
Since angle_a
, angle_b
, and angle_c
are stored as
128-bit decimals, the output of
$degreesToRadians
is a 128-bit decimal.