MongoDB聚合运算符:$exp

文章目录


$exp聚合运算符返回自然常数或欧拉数e的幂值(次方)的结果

语法

{ $exp: <exponent> }

<exponent>为指数,可以是任何数值表达式。

使用

如果参数为null或引用的字段不存在,$exp返回null,如果参数解析为NaN$exp也返回NaN,如下:

参数 结果
{$exp: 0} 1
{$exp: 2} 7.38905609893065
{ $exp: -2 } 0.1353352832366127

举例

使用下面的脚本创建accounts集合:

db.accounts.insertMany( [
   { _id: 1, interestRate: .08, presentValue: 10000 },
   { _id: 2, interestRate: .0825, presentValue: 250000 },
   { _id: 3, interestRate: .0425, presentValue: 1000 }
] )

下面的例子计算连续复利的实际利率:

db.accounts.aggregate( [ { $project: { effectiveRate: { $subtract: [ { $exp: "$interestRate"}, 1 ] } } } ] )

返回结果如下:

{ "_id" : 1, "effectiveRate" : 0.08328706767495864 }
{ "_id" : 2, "effectiveRate" : 0.08599867343905654 }
{ "_id" : 3, "effectiveRate" : 0.04341605637367807 }

使用下面的脚本创建``集合:

相关推荐

  1. MongoDB聚合运算符:$exp

    2024-03-15 16:52:02       40 阅读
  2. MongoDB聚合运算符:$add

    2024-03-15 16:52:02       55 阅读
  3. MongoDB聚合运算符:$arrayToObject

    2024-03-15 16:52:02       53 阅读
  4. MongoDB聚合运算符;$dateToParts

    2024-03-15 16:52:02       53 阅读
  5. MongoDB聚合运算符:$dayOfWeek

    2024-03-15 16:52:02       55 阅读
  6. MongoDB聚合运算符:$dayOfMonth

    2024-03-15 16:52:02       52 阅读
  7. MongoDB聚合运算符;$dateToString

    2024-03-15 16:52:02       48 阅读
  8. MongoDB聚合运算符:$dayOfYear

    2024-03-15 16:52:02       48 阅读
  9. MongoDB聚合运算符:$denseRank

    2024-03-15 16:52:02       42 阅读
  10. MongoDB聚合运算符:$dateTrunc

    2024-03-15 16:52:02       46 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-03-15 16:52:02       98 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-03-15 16:52:02       106 阅读
  3. 在Django里面运行非项目文件

    2024-03-15 16:52:02       87 阅读
  4. Python语言-面向对象

    2024-03-15 16:52:02       96 阅读

热门阅读

  1. 【大数据】一、大数据环境配置

    2024-03-15 16:52:02       45 阅读
  2. Alias许可数量计算

    2024-03-15 16:52:02       46 阅读
  3. React.FC介绍

    2024-03-15 16:52:02       33 阅读
  4. php 微信扫码支付

    2024-03-15 16:52:02       48 阅读
  5. XML常用介绍

    2024-03-15 16:52:02       43 阅读
  6. Python中的增强现实(AR)技术和应用

    2024-03-15 16:52:02       38 阅读
  7. buuctf 部分web题

    2024-03-15 16:52:02       36 阅读
  8. 蓝桥杯2023年-阶乘的和(数学推理,C++)

    2024-03-15 16:52:02       38 阅读
  9. 一文了解什么是函数柯里化

    2024-03-15 16:52:02       42 阅读
  10. CSS 02

    CSS 02

    2024-03-15 16:52:02      30 阅读