- Reference >
- Operators >
- Aggregation Pipeline Operators >
- $log (aggregation)
$log (aggregation)¶
On this page
Definition¶
-
$log
¶ New in version 3.2.
Calculates the log of a number in the specified base and returns the result as a double.
$log
has the following syntax:The
<number>
expression can be any valid expression as long as it resolves to a non-negative number.The
<base>
expression can be any valid expression as long as it resolves to a positive number greater than1
.For more information on expressions, see Expressions.
Behavior¶
If either argument resolves to a value of null
or refers to a field that is
missing, $log
returns null
. If either argument resolves to
NaN
, $log
returns NaN
.
Example | Results |
---|---|
{ $log: [ 100, 10 ] } |
2 |
{ $log: [ 100, Math.E ] } where Math.E is a JavaScript
representation for e. |
4.605170185988092 |