此版本的文档已存档,不再提供支持。要升级5.0部署,请参阅 MongoDB 6.0升级程序。
定义
行为
如果参数解析为 null 的值或引用了缺失的字段,$exp 返回 null。如果参数解析为 NaN,$exp 会返回 NaN。
例子 | 结果 |
|---|---|
|
|
|
|
|
|
例子
一个名为 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 }