$log - Amazon DocumentDB

기계 번역으로 제공되는 번역입니다. 제공된 번역과 원본 영어의 내용이 상충하는 경우에는 영어 버전이 우선합니다.

$log

버전 4.0의 새 버전입니다.

Amazon DocumentDB의 $log 연산자는 숫자의 자연 로그를 계산합니다. 지정된 숫자의 base-e 로그를 반환합니다.

파라미터

  • expression: 자연 로그를 계산할 숫자입니다.

  • base: 로그를 계산하는 기본 값입니다.

예제(MongoDB 쉘)

다음 예제에서는 $log 연산자를 사용하여 숫자의 자연 로그를 계산하는 방법을 보여줍니다.

샘플 문서 생성

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

쿼리 예제

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

출력

[ { "_id" : 1, "naturalLog" : 1 }, { "_id" : 2, "naturalLog" : 2 }, { "_id" : 3, "naturalLog" : 2.9999999999999996 } ]

코드 예제

$log 명령을 사용하기 위한 코드 예제를 보려면 사용하려는 언어의 탭을 선택합니다.

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: { $log: ["$value", 10] } }} ]).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": { "$log": ["$value", 10] } }} ])) print(result) client.close() example()