$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.

CategoryMath
MongoDB Version1.0+
Example Languagemongosh (Shell)

📝 Syntax

{ $log10: <numeric-expression> }

⚙️ Parameters

numeric valueA 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

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.
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%

🙏 帮我们做得更好

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

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