$pow (Power)

Last updated: 2026-10-09

$pow (Power)

$pow raises a number to a power. It takes two arguments — the base and the exponent — returning base raised to exponent. It is used for area and volume math, compound interest, and scaling, such as squaring a radius for a circle area or shifting values by powers of ten. An exponent of 0 yields 1, and zero to the power of zero returns 1 in MongoDB. Be aware that a negative base with a non-integer exponent returns null, since the result is not a real number. Any null or missing argument yields null.

CategoryMath
MongoDB Version1.0+
Example Languagemongosh (Shell)

📝 Syntax

{ $pow: [ <base>, <exponent> ] }

⚙️ Parameters

baseA numeric value or an expression resolving to one.
exponentThe exponent expression; it must be an integer when the base is negative.

Returns:The base raised to the exponent; null for a negative base with a non-integer exponent, or null and missing arguments

▶ Example

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

// $pow: circle area from squared radius (pi as 3.14)
db.shapes.aggregate([
  { $project: {
      area: { $multiply: [3.14, { $pow: ['$radius', 2] }] }
  } }
])

Output:

{ '_id': 1, 'area': 28.26 }
{ '_id': 2, 'area': 12.56 }

📌 Notes

More hands-on cases coming soon.

📚 Related Tutorials

❓ FAQ

QHow do I take a square root with $pow?
APass 0.5 as the exponent, so $pow: [9, 0.5] gives 3; or use the dedicated $sqrt.
QDoes $pow support negative bases?
AWith a negative base the exponent must be an integer; otherwise the result is not real and returns null.
QWhat does $pow return for an exponent of zero?
AAny base to the power of zero is 1, and zero to the power of zero is also 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%

🙏 帮我们做得更好

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

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