此版本的文档已存档,不再提供支持。要升级5.0部署,请参阅 MongoDB 6.0升级程序。
$asin返回值的反正弦。
$asin通过以下语法实现:{ $asin: <expression> } $asin接受解析为-1和1之间数字的任何有效表达式,例如-1 <= value <= 1。$asin以弧度为单位返回值。使用$radiansToDegrees操作符,将输出值从弧度转换为度数。默认情况下,
$asin以double形式返回值。 只要<expression>解析为128位十进制值,$asin也可以返回128位十进制值。有关表达式的更多信息,请参阅表达式。
行为
如果参数解析为 null 值或引用了缺失的字段,则 $asin 返回 null。如果参数解析为 NaN,则 $asin 返回 NaN。如果参数值超出了 [-1, 1] 范围,$asin 会抛出错误。
例子 | 结果 | |||
|---|---|---|---|---|
|
| |||
|
| |||
or
| 抛出一条类似以下格式化输出的错误消息: |
例子
trigonometry 集合包含一个文档,该文档存储直角三角形的三条边:
{ "_id" : ObjectId("5c50782193f833234ba90d85"), "side_a" : NumberDecimal("3"), "side_b" : NumberDecimal("4"), "hypotenuse" : NumberDecimal("5") }
以下聚合操作使用$asin表达式计算与side_a相反的角度,并使用$addFields管道阶段将其添加到输入文档。
db.trigonometry.aggregate([ { $addFields : { "angle_a" : { $radiansToDegrees : { $asin : { $divide : [ "$side_a", "$hypotenuse" ] } } } } } ])
$radiansToDegrees表达式将$asin返回的弧度值转换为以度为单位的等效值。
该命令返回以下输出:
{ "_id" : ObjectId("5c50782193f833234ba90d85"), "side_a" : NumberDecimal("3"), "side_b" : NumberDecimal("4"), "hypotenuse" : NumberDecimal("5"), "angle_a" : NumberDecimal("36.86989764584402129685561255909341") }
trigonometry 集合包含一个文档,该文档存储直角三角形的三条边:
{ "_id" : ObjectId("5c50782193f833234ba90d85"), "side_a" : NumberDecimal("3"), "side_b" : NumberDecimal("4"), "hypotenuse" : NumberDecimal("5") }
以下聚合操作使用$asin表达式计算与side_a相邻的角度,并使用$addFields管道阶段将其添加到输入文档。
db.trigonometry.aggregate([ { $addFields : { "angle_a" : { $asin : { $divide : [ "$side_a", "$hypotenuse" ] } } } } ])
该命令返回以下输出:
{ "_id" : ObjectId("5c50782193f833234ba90d85"), "side_a" : NumberDecimal("3"), "side_b" : NumberDecimal("4"), "hypotenuse" : NumberDecimal("5"), "angle_a" : NumberDecimal("0.6435011087932843868028092287173226") }