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

$asin(表达式操作符)

$asin

返回值的反正弦。

$asin 通过以下语法实现:

{ $asin: <expression> }

$asin-1可接受解析为 和1 之间数字的任何有效表达式,例如-1 <= value <= 1

$asin以弧度为单位返回值。使用$radiansToDegrees 操作符将输出值从弧度转换为度数。

默认下,$asin 128$asin返回double<expression> 128形式的值。只要 解析为 位十进制值, 也可以返回 位十进制值。

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

如果参数解析为null 的值或引用了缺失的字段,$asin 将返回null 。如果参数解析为NaN$asin 将返回NaN 。如果参数解析为超出[-1, 1] (含)边界的值,则$asin 会引发错误。

例子
结果

{ $asin: NaN }

NaN

{ $asin: null }

null

{ $asin : Infinity}

or

{ $asin : -Infinity }

抛出一条类似以下格式化输出的错误消息:

"errmsg" :
"Failed to optimize pipeline :: caused by :: cannot
apply $asin to -inf, value must in [-1,1]"

trigonometry 集合包含一个文档,该文档存储直角三角形的三条边:

{
"_id" : ObjectId("5c50782193f833234ba90d85"),
"side_a" : Decimal128("3"),
"side_b" : Decimal128("4"),
"hypotenuse" : Decimal128("5")
}

以下聚合操作使用$asin 表达式计算与side_a 相反的角度,并使用$addFields 管道阶段将其添加到输入文档。

db.trigonometry.aggregate([
{
$addFields : {
"angle_a" : {
$radiansToDegrees : {
$asin : {
$divide : [ "$side_a", "$hypotenuse" ]
}
}
}
}
}
])

$radiansToDegrees表达式将$asin 返回的弧度值转换为等效的度数值。

该命令返回以下输出:

{
"_id" : ObjectId("5c50782193f833234ba90d85"),
"side_a" : Decimal128("3"),
"side_b" : Decimal128("4"),
"hypotenuse" : Decimal128("5"),
"angle_a" : Decimal128("36.86989764584402129685561255909341")
}

由于side_ahypotenuse 128存储为$asin 位十进制数,因此 的输出为128 位十进制数。

trigonometry 集合包含一个文档,该文档存储直角三角形的三条边:

{
"_id" : ObjectId("5c50782193f833234ba90d85"),
"side_a" : Decimal128("3"),
"side_b" : Decimal128("4"),
"hypotenuse" : Decimal128("5")
}

以下聚合操作使用$asin 表达式计算与side_a 相邻的角度,并使用$addFields 管道阶段将其添加到输入文档。

db.trigonometry.aggregate([
{
$addFields : {
"angle_a" : {
$asin : {
$divide : [ "$side_a", "$hypotenuse" ]
}
}
}
}
])

该命令返回以下输出:

{
"_id" : ObjectId("5c50782193f833234ba90d85"),
"side_a" : Decimal128("3"),
"side_b" : Decimal128("4"),
"hypotenuse" : Decimal128("5"),
"angle_a" : Decimal128("0.6435011087932843868028092287173226")
}

由于side_ahypotenuse 128存储为$asin 位十进制数,因此 的输出为128 位十进制数。

给本页内容打分

在此页面上