The $atanh operator returns the inverse hyperbolic tangent of a number in MongoDB aggregation pipelines. It is the reverse of $tanh and is commonly used for data transforms and statistical modeling.
01
Inverse atanh
Reverse of hyperbolic tangent.
02
Syntax
One expression inside $atanh.
03
Input Range
Values between -1 and 1.
04
$project Stage
Add computed fields easily.
05
Use Cases
Stats, ML, transforms.
06
Edge Case
atanh(0) = 0
Fundamentals
Definition and Usage
In MongoDB’s aggregation framework, the $atanh operator computes the inverse hyperbolic tangent of a numeric expression. If tanh(y) = x, then atanh(x) = y. For example, $atanh(0.5) returns approximately 0.549, and $atanh(0) returns 0.
💡
Beginner Tip
Do not confuse $atanh with $atan. $atanh is hyperbolic math (like Math.atanh()), while $atan is regular trigonometry. They have different input rules and meanings.
Foundation
📝 Syntax
The $atanh operator takes one numeric expression:
mongosh
{ $atanh: <expression> }
Syntax Rules
$atanh — returns the inverse hyperbolic tangent of the expression.
<expression> — must evaluate to a number strictly between -1 and 1.
Use it inside stages like $project, $addFields, or $set.
If the input is null, the result is null.
Values of exactly 1, -1, or outside the range return null or NaN.
⚠️ Valid Input Range: -1 to 1 (Exclusive at Boundaries)
$atanh only accepts values between -1 and 1. The endpoints themselves are undefined.
$atanh: 0.5 → 0.549(valid)
$atanh: 0 → 0(valid)
$atanh: 1 → null(undefined!)
$atanh: 1.2 → null(out of range!)
Cheat Sheet
⚡ Quick Reference
Question
Answer
Operator type
Aggregation expression operator (hyperbolic)
Syntax
{ $atanh: <expression> }
Input range
Greater than -1 and less than 1
Inverse of
$tanh
Common stages
$project, $addFields, $set
Example
{
$atanh: 0.5
}
≈ 0.549
Negative
{
$atanh: -0.5
}
≈ -0.549
Zero
{
$atanh: 0
}
Returns 0
Null input
{
$atanh: null
}
Returns null
Hands-On
Examples Gallery
Compute inverse hyperbolic tangent on sample values between -1 and 1, including positive, negative, and zero inputs.
📚 Basic Computation
Use a values collection and compute $atanh for each numeric field with $project.
Sample Input Documents
Suppose you have a values collection with a numeric x field:
Statistical analysis — Fisher z-transform on correlation coefficients or normalized data.
Machine learning — preprocessing features bounded between -1 and 1 before modeling.
Data normalization — reverse a $tanh scaling step to recover original magnitudes.
🧠 How $atanh Works
1
MongoDB reads the value
The pipeline evaluates the input — a field like "$x" or a numeric expression between -1 and 1.
Input
2
$atanh computes the inverse
MongoDB applies the inverse hyperbolic tangent function. Values outside (-1, 1) return null or NaN.
Transform
3
The result is stored in the pipeline
The computed value is written to the field you define in $project or $addFields.
Output
=
📈
Transformed numeric data
Use the result for grouping, averaging, or further pipeline stages.
Wrap Up
Conclusion
The $atanh operator is a useful hyperbolic math tool in MongoDB aggregation pipelines. It reverses $tanh scaling, supports the Fisher z-transform in statistics, and handles negative values naturally within its valid domain.
For beginners, remember: input must be between -1 and 1 (not including the endpoints), atanh(0) = 0, and do not confuse $atanh with the trigonometric $atan operator.
Validate that input values are between -1 and 1 before applying
Remember atanh(0) = 0 when checking results
Use $round for readable output values
Pair with $tanh to verify round-trip calculations
Guard with $cond in production pipelines
❌ Don’t
Confuse $atanh with $atan (different functions)
Pass values of exactly 1 or -1 without handling undefined results
Pass correlation values of ±1 without a guard
Use $atanh as a query filter outside expressions
Forget that values near ±1 produce very large outputs
Summary
Key Takeaways
Knowledge Unlocked
Five things to remember about $atanh
Use these points when working with hyperbolic math in MongoDB.
5
Core concepts
📈01
Inverse atanh
Reverse of $tanh.
Purpose
📝02
Simple Syntax
{ $atanh: expr }
Syntax
📏03
Input Range
Between -1 and 1.
Domain
🔢04
Odd Function
atanh(-x) = -atanh(x).
Property
⚠05
Not $atan
Hyperbolic, not trig.
Important
❓ Frequently Asked Questions
$atanh returns the inverse hyperbolic tangent (arc hyperbolic tangent) of a number. It is the reverse of $tanh and is used in aggregation expression stages like $project and $addFields.
The syntax is { $atanh: <expression> }. The expression can be a field reference like "$x", a literal number, or another numeric expression.
$atanh only works for values strictly between -1 and 1. Input of exactly 1, -1, or anything outside that range returns null or NaN.
atanh(0) equals 0. This is a useful edge case when validating pipeline results.
No. $atanh is inverse hyperbolic tangent (hyperbolic math). $atan is inverse tangent (trigonometry). They are different functions with different input rules.