On this page本页内容
$degreesToRadians
New in version 4.2.在版本4.2中新增。
Converts an input value measured in degrees to radians.将以度为单位测量的输入值转换为弧度。
$degreesToRadians
has the following syntax:语法如下:
{ $degreesToRadians: <expression> }
$degreesToRadians
takes any valid expression that resolves to a number.接受解析为数字的任何有效表达式。
By default 默认情况下,$degreesToRadians
returns values as a double
. $degreesToRadians
以double
返回值。$degreesToRadians
can also return values as a 128-bit decimal as long as the 只要<expression>
resolves to a 128-bit decimal value.<expression>
解析为128位十进制值,也可以以128位十进制返回值。
For more information on expressions, see Expressions.有关表达式的详细信息,请参阅表达式。
null
, NaN
, and +/- Infinity
If the argument resolves to a value of 如果参数解析为null
or refers to a field that is missing, $degreesToRadians
returns null
. null
值或引用缺少的字段,$degreesToRadians
将返回null
值。If the argument resolves to 如果参数解析为NaN
, $degreesToRadians
returns NaN
. NaN
,$degreesToRadians
返回NaN
。If the argument resolves to negative or positive infinity, 如果参数解析为负或正无穷大,$degreesToRadians
negative or positive infinity respectively.$degreesToRadians
分别表示负或正无限大。
{ $degreesToRadians: NaN } | NaN |
{ $degreesToRadians: null } | null |
{ $degreesToRadians : Infinity} | Infinity |
{ $degreesToRadians : -Infinity } | -Infinity |
The trigonometry
collection contains a document that contains three angles measured in degrees:trigonometry
集合包含一个文档,其中包含以度为单位测量的三个角度:
{ "angle_a" : NumberDecimal("53.13010235415597870314438744090659"), "angle_b" : NumberDecimal("36.86989764584402129685561255909341"), "angle_c" : NumberDecimal("90") }
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.trigonometry
表达式将每个值转换为其弧度等效值,并使用$addFields
管道阶段将它们添加到输入文档中。
db.trigonometry.aggregate([ { $addFields: { "angle_a_rad" : { $degreesToRadians : "$angle_a"}, "angle_b_rad" : { $degreesToRadians : "$angle_b"}, "angle_c_rad" : { $degreesToRadians : "$angle_c"} } } ])
The operation returns the following document:运算返回以下文档:
{ "_id" : ObjectId("5c50aec71c75c59232b3ede4"), "angle_a" : NumberDecimal("53.13010235415597870314438744090660"), "angle_b" : NumberDecimal("36.86989764584402129685561255909341"), "angle_c" : NumberDecimal("90"), "angle_a_rad" : NumberDecimal("0.9272952180016122324285124629224290"), "angle_b_rad" : NumberDecimal("0.6435011087932843868028092287173227"), "angle_c_rad" : NumberDecimal("1.570796326794896619231321691639752") }
Since 由于angle_a
, angle_b
, and angle_c
are stored as 128-bit decimals, the output of $degreesToRadians
is a 128-bit decimal.angle_a
、angle-b
和angle-c
存储为128位十进制数,因此$degreesToRadians
的输出是128位小数。