Database Manual / Reference / Query Language / Expressions

$radiansToDegrees (aggregation)(聚合)

Definition定义

$radiansToDegrees

Converts an input value measured in radians to degrees.将以弧度为单位的输入值转换为度。

$radiansToDegrees has the following syntax:具有以下语法:

{ $radiansToDegrees: <expression> }

$radiansToDegrees takes any valid expression that resolves to a number.接受解析为数字的任何有效表达式

By default $radiansToDegrees returns values as a double. $radiansToDegrees can also return values as a 128-bit decimal as long as the <expression> resolves to a 128-bit decimal value.默认情况下,$radiansToDegrees返回的值为double。只要<expression>解析为128位十进制值$radiansToDegrees也可以返回128位十进制的值。

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, $radiansToDegrees returns null. If the argument resolves to NaN, $radiansToDegrees returns NaN. 如果参数解析为null值或引用缺少的字段,$radiansToDegrees将返回null。如果参数解析为NaN$radiansToDegrees将返回NaNIf the argument resolves to negative or positive infinity, $radiansToDegrees negative or positive infinity respectively.如果参数解析为负无穷大或正无穷大,则$radiansToDegree分别解析为负无限大或正无限大。

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:trigonometry集合包含一个文档,其中包含以弧度测量的三个角度:

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

The following aggregation operation uses the $radiansToDegrees expression to convert each value to its degree equivalent and add them to the input document using the $addFields pipeline stage.以下聚合操作使用$radiansToDegrees表达式将每个值转换为其等效度数,并使用$addFields管道阶段将其添加到输入文档中。

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:该操作返回以下文档:

{
"_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, the output of $radiansToDegrees is a 128-bit decimal.由于angle_aangle_bangle_c存储为128位十进制,因此$radiansToDegrees的输出是128位十进制。