$log10 is a MongoDB aggregation expression that returns the base-10 logarithm of a number. Example: log10(100) = 2 because 10² = 100. It is a shortcut for { $log: [ number, 10 ] }.
Remember
$log10 = logarithm base 10
{ $log10: <number> }
// same as:
{ $log: [ <number>, 10 ] }
number → non-negative
result → double (usually)
{ $log10: 1 } → 0
{ $log10: 10 } → 1
{ $log10: 100 } → 2
{ $log10: 1000 } → 3
null / missing → null
NaN → NaN
Use the result for scaling, orders of magnitude, or formulas like pH.
Piece
Required?
Role
Number
Yes
Value to take log10 of (≥ 0)
Result
—
Double (or decimal if input is decimal)
Pseudocode
Pseudocode
for each document:
n = evaluate(numberExpression)
if n is null or missing:
result = null
else if n is NaN:
result = NaN
else:
result = log10(n) // base-10 logarithm
emit { ..., field: result }
Reference
Cheat Sheet
Keep these facts handy while computing base-10 logs.
A reading stores value: 100. We want the base-10 logarithm.
Calculation
Document:
{ value: 100 }
$log10: "$value"
Ask: 10 to what power equals 100?
10^2 = 100
Result:
2
Same as: { $log: [ 100, 10 ] } → 2 ✓
Code
MongoDB Examples
We use one sample document. First we store it, then we compute $log10, then we use it in a simple pH-style formula. Run these in mongosh after inserting the sample data once.
Example 1 — Sample Data
Imagine one lab sample with value 100 and hydrogen-ion concentration H3O = 0.001.
Base-10 log is inexpensive compared with large sorts or joins. Filter early with $match when only some documents need the field.
Remember
Key Takeaways
Role: number → base-10 logarithm (double).
Syntax:{ $log10: "$value" }.
Same as:{ $log: [ "$value", 10 ] }.
Domain: non-negative number.
One line:$log10 answers “10 to what power equals this number?”
Frequently Asked Questions
$log10 returns the base-10 logarithm of a number. For example, { $log10: 100 } returns 2 because 10² = 100. Use it inside aggregation stages such as $project and $addFields.
The syntax is { $log10: <number> }. The argument can be a field path like "$value", a literal, or another numeric expression. The result is typically a double.
$log10 is a shortcut for base 10 only. $log needs two arguments — number and base — so { $log10: "$value" } equals { $log: [ "$value", 10 ] }.
The input must resolve to a non-negative number. log10(1) is 0. Null or missing input returns null; NaN returns NaN. Prefer positive numbers for normal finite results.
Yes in spirit. Both compute base-10 log. In MongoDB you write { $log10: "$value" } inside an aggregation expression.
Use $log10 inside expression stages such as $project, $addFields, and $set when scaling data, normalizing skewed values, or computing pH-style formulas with -log10(concentration).