On this page本页内容
$ln
Calculates the natural logarithm ln (i.e log e) of a number and returns the result as a double.计算数字的自然对数ln(即log e),并以双精度形式返回结果。
$ln
has the following syntax:语法如下:
{ $ln: <number> }
The <number>
expression can be any valid expression as long as it resolves to a non-negative number. <number>
表达式可以是任何有效的表达式,只要它解析为非负数。For more information on expressions, see Expressions.有关表达式的详细信息,请参阅表达式。
$ln
is equivalent to 等效于$log: [ <number>, Math.E ]
expression, where Math.E
is a JavaScript representation for Euler's number e.$log: [ <number>, Math.E ]
表达式,其中Math.E
是欧拉数字e的JavaScript表示。
If the argument resolves to a value of 如果参数解析为null
or refers to a field that is missing, $ln
returns null
. null
值或引用缺少的字段,$ln
将返回null
。If the argument resolves to 如果参数解析为NaN,NaN
, $ln
returns NaN
.$ln
将返回NaN
。
{ $ln: 1 } | 0 |
{ $ln: Math.E } Math.E is a JavaScript representation for e.Math.E 是e的JavaScript表示形式。 | 1 |
{ $ln: 10 } | 2.302585092994046 |
A collection 集合sales
contains the following documents:sales
包含以下文档:
{ _id: 1, year: "2000", sales: 8700000 } { _id: 2, year: "2005", sales: 5000000 } { _id: 3, year: "2010", sales: 6250000 }
The following example transforms the 以下示例转换sales
data:sales
数据:
db.sales.aggregate( [ { $project: { x: "$year", y: { $ln: "$sales" } } } ] )
The operation returns the following results:该操作返回以下结果:
{ "_id" : 1, "x" : "2000", "y" : 15.978833583624812 } { "_id" : 2, "x" : "2005", "y" : 15.424948470398375 } { "_id" : 3, "x" : "2010", "y" : 15.648092021712584 }