$log10 (Base-10 Log)
Last updated: 2026-10-09
$log10 (Base-10 Log)
$log10 returns the base-10 logarithm of a number. It is used for order-of-magnitude checks, decibel math, and data compression, such as taking the common log of page views to compare orders of magnitude. A null or missing argument yields null; the input must be positive — zero or negative values return null. It is a special case of $log with a fixed base of 10, so no base argument is needed and the code stays concise. Alongside $ln and $log2 it lets you pick the right base.
| Category | Math |
|---|---|
| MongoDB Version | 1.0+ |
| Example Language | mongosh (Shell) |
📝 Syntax
{ $log10: <numeric-expression> }
⚙️ Parameters
| numeric value | A numeric value or an expression resolving to one; must be greater than 0. |
|---|
Returns:The base-10 logarithm of the input; null for non-positive, null, or missing input
▶ Example
Run the commands below in your local mongosh (requires a running mongod):
// $log10: common log of page views
db.traffic.aggregate([
{ $project: {
logViews: { $log10: '$views' }
} }
])
Output:
{ '_id': 1, 'logViews': 6 }
{ '_id': 2, 'logViews': 5.301029995663981 }
📌 Notes
- The base is fixed at 10, equivalent to $log: [x, 10]
- The input must be greater than 0
- Null or missing arguments yield null
🏷️ Related Tags
💡 Related Cases
More hands-on cases coming soon.
📚 Related Tutorials
❓ FAQ
QHow are $log10 and $log related?
A$log10 is simply $log with the base fixed to 10.
QWhat does $log10 return for negative input?
AIt returns null; logarithms are only defined for positive numbers.
QWhat is $log10(1000)?
AIt is 3, since 10 raised to the power of 3 is 1000.