View a markdown version of this page

$atan - Amazon DocumentDB

翻訳は機械翻訳により提供されています。提供された翻訳内容と英語版の間で齟齬、不一致または矛盾がある場合、英語版が優先します。

$atan

バージョン 8.0.1 から新規。

Amazon DocumentDB の $atan演算子は、値の逆タンジェント (arc タンジェント) を返します。

入力式は数値に解決する必要があります。

結果はラジアンです。学位を取得するには、 $radiansToDegreesを出力に適用します。

戻り値の型はdoubleデフォルトで です。入力が 128 ビットの 10 進数の場合、出力も 128 ビットの 10 進数です。

パラメータ

  • expression: 数値に解決される式。

動作

null と NaN

結果
{ $atan: NaN } NaN
{ $atan: null } null

入力が nullであるか、参照フィールドが欠落している場合、結果は ですnull。の入力により、 NaNが生成されますNaN

例 (MongoDB シェル)

次の例は、 $atan演算子を使用して値の配列を計算する方法を示しています。

サンプルドキュメントを作成する

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

クエリの例

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

出力

[ { "_id": 1, "angle": 0 }, { "_id": 2, "angle": 0.7853981633974483 }, { "_id": 3, "angle": -0.7853981633974483 } ]

コードの例

$atan 演算子を使用するコード例を表示するには、使用する言語のタブを選択します。

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: { "angle": { $atan: "$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': { 'angle': { '$atan': '$value' } }} ])) print(result) client.close() if __name__ == "__main__": main()