对于 AI 代理:可在 https://www.mongodb.com/zh-cn/docs/llms.txt 获取文档索引—通过在任何 URL 路径后添加 .md 可获取所有页面的 Markdown 版本。
Docs 菜单

$radiansToDegrees(表达式操作符)

$radiansToDegrees

将以弧度为单位测量的输入值转换为度数。

$radiansToDegrees 通过以下语法实现:

{ $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.

有关表达式的更多信息,请参阅表达式。

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. If the argument resolves to negative or positive infinity, $radiansToDegrees negative or positive infinity respectively.

例子
结果

{ $radiansToDegrees: NaN }

NaN

{ $radiansToDegrees: null }

null

{ $radiansToDegrees : Infinity}

Infinity

{ $radiansToDegrees : -Infinity }

-Infinity

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.

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

该操作将返回以下文档:

{
"_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.

给本页内容打分

在此页面上