View a markdown version of this page

$atanh - Amazon DocumentDB

本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。

$atanh

8.0.1 版的新功能。

Amazon DocumentDB 中的$atanh運算子會傳回值的反雙曲正切 (雙曲電弧正切)。

輸入表達式必須解析為 -11(包含) 範圍內的數字。超出此範圍的值會導致錯誤。

傳回類型預設為 double 。如果輸入是 128 位元的小數位數,則輸出也是 128 位元的小數位數。

參數

  • expression:解析為介於 -1和 之間的數字的表達式1,包含 。

Behavior (行為)

null、NaN 和 +/- Infinity

範例 結果
{ $atanh: NaN } NaN
{ $atanh: null } null
{ $atanh: 1 } Infinity
{ $atanh: -1 } -Infinity
{ $atanh: Infinity }{ $atanh: -Infinity } 擲回錯誤。

當輸入為 null或參考欄位遺失時,結果為 null。的輸入NaN會產生 NaN。邊界值 1-Infinity分別-1產生 Infinity和 。超出[-1, 1]範圍 (包括 ±Infinity) 的任何值都會導致錯誤。

範例 (MongoDB Shell)

下列範例顯示如何使用 $atanh運算子來計算值的反雙曲切線。

建立範例文件

db.values.insertMany([ { "_id": 1, "value": 0 }, { "_id": 2, "value": 0.5 }, { "_id": 3, "value": -0.5 } ]);

查詢範例

db.values.aggregate([ { $project: { "result": { $atanh: "$value" } }} ]);

輸出

[ { "_id": 1, "result": 0 }, { "_id": 2, "result": 0.5493061443340548 }, { "_id": 3, "result": -0.5493061443340548 } ]

程式碼範例

若要檢視使用 $atanh 運算子的程式碼範例,請選擇您要使用的語言標籤:

Node.js
const { MongoClient } = require('mongodb'); async function main() { const client = await MongoClient.connect('mongodb://<username>:<password>@<cluster-endpoint>:27017/?tls=true&tlsCAFile=global-bundle.pem&replicaSet=rs0&readPreference=secondaryPreferred&retryWrites=false'); const db = client.db('test'); const collection = db.collection('values'); const result = await collection.aggregate([ { $project: { "result": { $atanh: "$value" } }} ]).toArray(); console.log(result); await client.close(); } main();
Python
from pymongo import MongoClient def main(): client = MongoClient('mongodb://<username>:<password>@<cluster-endpoint>:27017/?tls=true&tlsCAFile=global-bundle.pem&replicaSet=rs0&readPreference=secondaryPreferred&retryWrites=false') db = client['test'] collection = db['values'] result = list(collection.aggregate([ { '$project': { 'result': { '$atanh': '$value' } }} ])) print(result) client.close() if __name__ == "__main__": main()