On this page本页内容
$exp
Raises Euler's number (i.e. e ) to the specified exponent and returns the result.将欧拉数(即e)幂乘到指定的指数并返回结果。
$exp
has the following syntax:语法如下:
{ $exp: <exponent> }
The <exponent>
expression can be any valid expression as long as it resolves to a number. <exponent>
表达式可以是任何有效的表达式,只要它解析为数字即可。For more information on expressions, see Expressions.有关表达式的详细信息,请参阅表达式。
If the argument resolves to a value of 如果参数解析为null
or refers to a field that is missing, $exp
returns null
. If the argument resolves to NaN
, $exp
returns NaN
.null
值或引用缺少的字段,$exp
将返回null
。如果参数解析为NaN
,$exp
返回NaN
。
{ $exp: 0 } | 1 |
{ $exp: 2 } | 7.38905609893065 |
{ $exp: -2 } | 0.1353352832366127 |
A collection named 名为accounts
contains the following documents:accounts
的集合包含以下文档:
{ _id: 1, rate: .08, pv: 10000 } { _id: 2, rate: .0825, pv: 250000 } { _id: 3, rate: .0425, pv: 1000 }
The following example calculates the effective interest rate for continuous compounding:以下示例计算连续复利的实际利率:
db.accounts.aggregate( [ { $project: { effectiveRate: { $subtract: [ { $exp: "$rate"}, 1 ] } } } ] )
The operation returns the following results:该操作返回以下结果:
{ "_id" : 1, "effectiveRate" : 0.08328706767495864 } { "_id" : 2, "effectiveRate" : 0.08599867343905654 } { "_id" : 3, "effectiveRate" : 0.04341605637367807 }