$exp (Exponential)

Last updated: 2026-10-09

$exp (Exponential)

$exp returns e raised to the given power, the exponential function e to the power of x, where e is approximately 2.71828. It is used for continuous compounding, exponential smoothing, and undoing natural logarithms. A null or missing argument yields null. $exp and $ln are inverses: $ln($exp(x)) equals x. Note that large exponents can overflow to Infinity, so scale the input with $divide beforehand to avoid losing precision.

CategoryMath
MongoDB Version1.0+
Example Languagemongosh (Shell)

📝 Syntax

{ $exp: <numeric-expression> }

⚙️ Parameters

exponentThe exponent expression; it may be positive or negative.

Returns:e raised to the power of the input; null when null or missing

▶ Example

Run the commands below in your local mongosh (requires a running mongod):

// $exp: restore original values from natural logs
db.sales.aggregate([
  { $project: {
      restored: { $exp: '$logAmount' }
  } }
])

Output:

{ '_id': 1, 'restored': 100 }
{ '_id': 2, 'restored': 20 }

📌 Notes

More hands-on cases coming soon.

📚 Related Tutorials

❓ FAQ

QHow are $exp and $ln related?
AThey are inverses, so $ln($exp(x)) restores x.
QWhat happens when $exp overflows?
AThe result becomes Infinity for huge exponents; scale the input down first.
QWhat is $exp(0)?
AIt is 1, since e to the power of zero is 1.
Web-Tutorial.com

Web-Tutorial Tech Team

A team of developers maintaining programming tutorials. Each tutorial is written and reviewed by developers with expertise in that field. We work to keep our content accurate and reliable — if you spot an issue, please let us know.

100%

🙏 帮我们做得更好

我们是刚上线的编程教程站,几个人的小团队,精力有限。页面虽经检查,难免还有疏漏——链接失效、排版错乱、内容有误、语言生硬……

如果您发现了,麻烦告诉我们,我们会在收到反馈后第一时间进行修复,再次感谢您的光临 🙏