$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.
| Category | Math |
|---|---|
| MongoDB Version | 1.0+ |
| Example Language | mongosh (Shell) |
📝 Syntax
{ $pow: [ <base>, <exponent> ] }
⚙️ Parameters
| base | A numeric value or an expression resolving to one. |
|---|---|
| exponent | The 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
- Zero to the power of zero returns 1
- A negative base with a non-integer exponent (such as -8 to the 1/3) returns null
- You can take a square root with a 0.5 exponent, but $sqrt reads better
🏷️ Related Tags
💡 Related Cases
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.