AI エージェント向け: ドキュメントインデックスは https://www.mongodb.com/ja-jp/docs/llms.txt で利用できます。すべてのページの markdown バージョンは、いずれかの URL パスに .md を追加することで利用できます。
Docs Menu

$sin(式 演算子)

$sin

ラジアンで測定された値のサインを返します。

$sin の構文は次のとおりです。

{ $sin: <expression> }

$sin takes any valid expression that resolves to a number. If the expression returns a value in degrees, use the $degreesToRadians operator to convert the result to radians.

$sinデフォルトでは、 は値をdouble として返します。$sin 128<expression>は、 が128 ビットの 10 進数値に解決される限り、 ビットの 10 進数として値を返すこともできます。

式の詳細については、「式 」を参照してください。

If the argument resolves to a value of null or refers to a field that is missing, $sin returns null. If the argument resolves to NaN, $sin returns NaN. If the argument resolves to negative or positive infinity, $sin throws an error.

結果

{ $sin: NaN }

NaN

{ $sin: null }

null

{ $sin : Infinity}

or

{ $sin : -Infinity }

次の形式の出力のようなエラーメッセージをスローします。

"errmsg" :
"Failed to optimize pipeline :: caused by :: cannot
apply $sin to -inf, value must in (-inf,inf)"

trigonometryコレクションには、便宜的と 1 つの角度を直角三角形に保存するドキュメントが含まれています。

{
"_id" : ObjectId("5c50782193f833234ba90d85"),
"angle_a" : Decimal128("53.13010235415597870314438744090659"),
"hypotenuse" : Decimal128("5")
}

The following aggregation operation uses the $sin expression to calculate the side opposite to angle_a and add it to the input document using the $addFields pipeline stage.

db.trigonometry.aggregate([
{
$addFields : {
"side_b" : {
$multiply : [
{ $sin : {$degreesToRadians : "$angle_a"} },
"$hypotenuse"
]
}
}
}
])

$degreesToRadians式は、 angle_aの度の値をラジアン単位の同等の値に変換します。

このコマンドは、次の出力を返します。

{
"_id" : ObjectId("5c50782193f833234ba90d85"),
"angle_a" : Decimal128("53.13010235415597870314438744090659"),
"side_b" : Decimal128("4.000000000000000000000000000000000"),
"hypotenuse" : Decimal128("5"),
}

angle_aと はhypotenuse 128ビットの 10 進数として保存されているため、$sin の出力は128 ビットの 10 進数になります。

trigonometryコレクションには、便宜的と 1 つの角度を直角三角形に保存するドキュメントが含まれています。

{
"_id" : ObjectId("5c50782193f833234ba90d85"),
"angle_a" : Decimal128("0.9272952180016122324285124629224288"),
"hypotenuse" : Decimal128("5")
}

The following aggregation operation uses the $sin expression to calculate the side opposite to angle_a and add it to the input document using the $addFields pipeline stage.

db.trigonometry.aggregate([
{
$addFields : {
"side_b" : {
$multiply : [
{ $sin : "$angle_a" },
"$hypotenuse"
]
}
}
}
])

このコマンドは、次の出力を返します。

{
"_id" : ObjectId("5c50782193f833234ba90d85"),
"angle_a" : Decimal128("0.9272952180016122324285124629224288"),
"side_b" : Decimal128("4.000000000000000000000000000000000"),
"hypotenuse" : Decimal128("5"),
}

Since angle_a and hypotenuse are stored as 128-bit decimals, the output of $sin is a 128-bit decimal.

このページを評価

項目一覧