The $cosh operator computes the hyperbolic cosine of a number in MongoDB aggregation pipelines. Use it for exponential growth models, catenary curves, and advanced math transformations on numeric data.
01
Hyperbolic Cosine
Exponential-style math.
02
Syntax
One expression inside $cosh.
03
Output ≥ 1
Always at least 1.
04
Even Function
cosh(-x) = cosh(x).
05
Use Cases
Growth, physics, stats.
06
vs $cos
Hyperbolic vs circular.
Fundamentals
Definition and Usage
In MongoDB’s aggregation framework, the $cosh operator returns the hyperbolic cosine of a numeric expression. The formula is cosh(x) = (ex + e-x) / 2. For example, cosh(0) = 1 and cosh(1) ≈ 1.543. Unlike circular cosine, the result is always greater than or equal to 1.
💡
Beginner Tip
Think of $cosh as MongoDB’s version of JavaScript’s Math.cosh(). Use it inside aggregation expression stages like $project or $addFields, not as a query filter.
Foundation
📝 Syntax
The $cosh operator takes one numeric expression:
mongosh
{ $cosh: <expression> }
Syntax Rules
$cosh — returns the hyperbolic cosine of the expression.
<expression> — a field reference, literal, or nested numeric expression.
Output is always ≥ 1 (minimum value is 1 at input 0).
$cosh is an even function: cosh(-x) = cosh(x).
Use inside stages like $project, $addFields, or $set.
$cosh(0) = 1 is the minimum. $cosh(-1) equals $cosh(1), confirming the even-function property.
Applications
🚀 Use Cases
Exponential growth analysis — model rapid increases in metrics, populations, or investments.
Physics and engineering — catenary curves, heat diffusion, and wave equations involving hyperbolic functions.
Statistics — transform data in advanced statistical pipelines that use hyperbolic math.
Signal processing — complementary to circular trig when analyzing non-periodic exponential signals.
🧠 How $cosh Works
1
MongoDB reads the input
The pipeline evaluates the expression — a field like "$x" or a numeric literal.
Input
2
$cosh applies the formula
MongoDB computes (ex + e-x) / 2 and returns a value ≥ 1.
Transform
3
The result is stored in the pipeline
The hyperbolic cosine is written to the field you define in $project or $addFields.
Output
=
📈
Hyperbolic value ready to use
Feed into $acosh for the inverse, or combine with $sinh for full hyperbolic identities.
Wrap Up
Conclusion
The $cosh operator brings hyperbolic cosine math into MongoDB aggregation pipelines. Remember that output is always at least 1, values grow exponentially for large inputs, and the function is symmetric around zero.
Do not confuse $cosh with $cos (circular, bounded) or $acosh (inverse, requires input ≥ 1). Pick the operator that matches your mathematical model.
Leverage the even-function property for signed data
Pair with $sinh for hyperbolic identity calculations
❌ Don’t
Confuse $cosh with $cos (different math entirely)
Expect bounded output like circular cosine (-1 to 1)
Use $acosh on $cosh output without checking the domain
Assume small inputs stay near 1 — growth accelerates quickly
Forget that null input returns null
Summary
Key Takeaways
Knowledge Unlocked
Five things to remember about $cosh
Use these points when working with hyperbolic cosine in MongoDB.
5
Core concepts
📈01
Hyperbolic
Exponential growth.
Purpose
📝02
{ $cosh: x }
One expression.
Syntax
📏03
Output ≥ 1
Min at cosh(0).
Range
🛠04
Even Function
cosh(-x) = cosh(x).
Property
⚠05
Not $cos
Hyperbolic vs circular.
Important
❓ Frequently Asked Questions
$cosh returns the hyperbolic cosine of a numeric value. Unlike circular cosine, hyperbolic cosine grows exponentially and is always greater than or equal to 1.
The syntax is { $cosh: <expression> }. The expression can be a field reference like "$x", a literal number, or another numeric expression.
$cos is circular trigonometry (output -1 to 1, periodic). $cosh is hyperbolic (output >= 1, grows exponentially). They solve different math problems.
Yes. cosh(-x) equals cosh(x). In a pipeline, $cosh applied to a negative field returns the same result as the positive value.
$cosh returns null when the input is null. It does not throw an error.