$ln - Amazon DocumentDB

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

$ln

バージョン 4.0 の新機能。

Amazon DocumentDB の$ln演算子は、指定された数の自然対数 (ベース e) を計算します。数値の対数をベース e に返します。

パラメータ

  • expression: 自然対数を計算する数値。

例 (MongoDB シェル)

次の例は、$log演算子を使用して数値の自然対数を計算する方法を示しています。

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

db.numbers.insertMany([ { _id: 1, value: 10 }, { _id: 2, value: 100 }, { _id: 3, value: 1000 } ]);

クエリの例

db.numbers.aggregate([ { $project: { _id: 1, naturalLog: { $ln: "$value" } }} ]);

出力

[ { "_id" : 1, "naturalLog" : 2.302585092994046 }, { "_id" : 2, "naturalLog" : 4.605170185988092 }, { "_id" : 3, "naturalLog" : 6.907755278982137 } ]

コードの例

$ln コマンドを使用するコード例を表示するには、使用する言語のタブを選択します。

Node.js
const { MongoClient } = require('mongodb'); async function example() { 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('numbers'); const result = await collection.aggregate([ { $project: { _id: 1, naturalLog: { $ln: "$value" } }} ]).toArray(); console.log(result); client.close(); } example();
Python
from pymongo import MongoClient def example(): 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.numbers result = list(collection.aggregate([ { "$project": { "_id": 1, "naturalLog": { "$ln": "$value" } }} ])) print(result) client.close() example()