$exp (aggregation)
On this page本页内容
Definition定义
$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.有关表达式的详细信息,请参阅表达式。
Behavior行为
If the argument resolves to a value of 如果参数解析为null
or refers to a field that is missing, $exp
returns null
. null
值或引用了缺失的字段,$exp
将返回null
。If the argument resolves to 如果参数解析为NaN
, $exp
returns NaN
.NaN
,$exp
将返回NaN
。
{ $exp: 0 } | 1 |
{ $exp: 2 } | 7.38905609893065 |
{ $exp: -2 } | 0.1353352832366127 |
Example实例
A collection named 名为accounts
contains the following documents:accounts
的集合包含以下文档:
db.accounts.insertMany( [
{ _id: 1, interestRate: .08, presentValue: 10000 },
{ _id: 2, interestRate: .0825, presentValue: 250000 },
{ _id: 3, interestRate: .0425, presentValue: 1000 }
] )
The following example calculates the effective interest rate for continuous compounding:以下示例计算连续复利的实际利率:
db.accounts.aggregate( [ { $project: { effectiveRate: { $subtract: [ { $exp: "$interestRate"}, 1 ] } } } ] )
The operation returns the following results:该操作返回以下结果:
{ "_id" : 1, "effectiveRate" : 0.08328706767495864 }
{ "_id" : 2, "effectiveRate" : 0.08599867343905654 }
{ "_id" : 3, "effectiveRate" : 0.04341605637367807 }