MongoDBでは、$atanh 集計パイプライン演算子は、値の双曲線アークタンジェント(逆双曲線タンジェント)を返します。
戻り値はラジアンです。
$atanh -1の間の数値に解決される有効な式を受け入れます および1 。
$atanh 演算子はMongoDB4.2で導入されました。
例
testというコレクションがあるとします。 次のドキュメントで:
{ "_id" : 1, "data" : 0.5 }
$atanhを使用できます dataの双曲線アークタンジェントを返す演算子 フィールド:
db.test.aggregate(
[
{ $match: { _id: 1 } },
{ $project: {
_id: 0,
hyperbolicArctangent: { $atanh: "$data" }
}
}
]
) 結果:
{ "hyperbolicArctangent" : 0.5493061443340549 } 度に変換
前述のように、$atanh 結果をラジアンで返します。 $radiansToDegreesを使用できます 結果を度で表示したい場合は演算子。
例:
db.test.aggregate(
[
{ $match: { _id: 1 } },
{ $project: {
_id: 0,
radians: { $atanh: "$data" },
degrees: { $radiansToDegrees: { $atanh: "$data" } }
}
}
]
) 結果:
{ "radians" : 0.5493061443340549, "degrees" : 31.472923730945382 } この例では、最初のフィールドは結果をラジアンで表示し、2番目のフィールドは結果を度で表示します。
128ビットの10進値
デフォルトでは、$atanh 演算子は値をdoubleとして返します 、ただし、式が128ビットの10進数値に解決される限り、128ビットの10進数として値を返すこともできます。
コレクションに次のドキュメントを追加するとします。
{ "_id" : 2, "data" : NumberDecimal("0.1301023541559787031443874490659") }
$atanhを実行してみましょう そのドキュメントに対する演算子:
db.test.aggregate(
[
{ $match: { _id: 2 } },
{ $project: {
_id: 0,
result: { $atanh: "$data" }
}
}
]
) 結果:
{ "result" : NumberDecimal("0.1308439651155512740523796431117568") } 出力は128ビットの10進数です。
範囲外の値
$atanh 演算子は、-1の間の数値に解決される有効な式を受け入れます および1 。その範囲外の値はエラーの原因になります。
コレクションに次のドキュメントを追加するとします。
{ "_id" : 3, "data" : 2 }
$atanhを実行してみましょう そのドキュメントに対する演算子:
db.test.aggregate(
[
{ $match: { _id: 3 } },
{ $project: {
_id: 0,
result: { $atanh: "$data" }
}
}
]
) 結果:
uncaught exception: Error: command failed: {
"ok" : 0,
"errmsg" : "cannot apply $atanh to 2, value must in [-1,1]",
"code" : 50989,
"codeName" : "Location50989"
} : aggregate failed :
example@sqldat.com/mongo/shell/utils.js:25:13
example@sqldat.com/mongo/shell/assert.js:18:14
example@sqldat.com/mongo/shell/assert.js:618:17
example@sqldat.com/mongo/shell/assert.js:708:16
example@sqldat.com/mongo/shell/db.js:266:5
example@sqldat.com/mongo/shell/collection.js:1046:12
@(shell):1:1 ヌル値
ヌル値はnullを返します $atanhを使用する場合 オペレーター。
コレクションに次のドキュメントを追加するとします。
{ "_id" : 4, "data" : null }
$atanhを実行してみましょう そのドキュメントに対する演算子:
db.test.aggregate(
[
{ $match: { _id: 4 } },
{ $project: {
_id: 0,
result: { $atanh: "$data" }
}
}
]
) 結果:
{ "result" : null }
結果がnullであることがわかります 。
NaN値
引数がNaNに解決された場合 、$atanh NaNを返します 。
例:
db.test.aggregate(
[
{ $match: { _id: 1 } },
{ $project: {
_id: 0,
result: { $atanh: 1 * "$data" }
}
}
]
) 結果:
{ "result" : NaN } 存在しないフィールド
$atanhの場合 存在しないフィールド、nullに対して演算子が適用されます 返されます。
例:
db.test.aggregate(
[
{ $match: { _id: 1 } },
{ $project: {
_id: 0,
result: { $atanh: "$name" }
}
}
]
) 結果:
{ "result" : null } インフィニティ
Infinityの提供 または-Infinity 範囲外のエラーが返されます(前に見たように)。
次のドキュメントをコレクションに追加するとします。
{ "_id" : 5, "data" : Infinity }
$atanhを実行してみましょう もう一度:
db.test.aggregate(
[
{ $match: { _id: 5 } },
{ $project: {
_id: 0,
result: { $atanh: "$data" }
}
}
]
) 結果:
uncaught exception: Error: command failed: {
"ok" : 0,
"errmsg" : "cannot apply $atanh to inf, value must in [-1,1]",
"code" : 50989,
"codeName" : "Location50989"
} : aggregate failed :
example@sqldat.com/mongo/shell/utils.js:25:13
example@sqldat.com/mongo/shell/assert.js:18:14
example@sqldat.com/mongo/shell/assert.js:618:17
example@sqldat.com/mongo/shell/assert.js:708:16
example@sqldat.com/mongo/shell/db.js:266:5
example@sqldat.com/mongo/shell/collection.js:1046:12
@(shell):1:1