MongoDB $acosh Operator

Beginner
⏱️ 9 min read
📚 Updated: Jul 2026
🎯 4 Examples
Hyperbolic Math

What You’ll Learn

The $acosh operator returns the inverse hyperbolic cosine of a number in MongoDB aggregation pipelines. It is the reverse of $cosh and is useful when analyzing exponential growth, decay, or other hyperbolic relationships in your data.

01

Inverse acosh

Reverse of hyperbolic cosine.

02

Syntax

One expression inside $acosh.

03

Input Range

Values must be ≥ 1.

04

$project Stage

Add computed fields easily.

05

Use Cases

Growth, finance, statistics.

06

Edge Case

acosh(1) = 0

Definition and Usage

In MongoDB’s aggregation framework, the $acosh operator computes the inverse hyperbolic cosine of a numeric expression. If cosh(y) = x, then acosh(x) = y. For example, $acosh(1) returns 0, and $acosh(2) returns approximately 1.317.

💡
Beginner Tip

Think of $acosh as MongoDB’s version of JavaScript’s Math.acosh(). Use it inside aggregation expression stages, not as a standalone query filter operator.

📝 Syntax

The $acosh operator takes one numeric expression:

mongosh
{ $acosh: <expression> }

Syntax Rules

  • $acosh — returns the inverse hyperbolic cosine of the expression.
  • <expression> — must evaluate to a number greater than or equal to 1.
  • Use it inside stages like $project, $addFields, or $set.
  • If the input is null, the result is null.
  • Values less than 1 return NaN.

⚠️ Valid Input Range: ≥ 1

$acosh is only defined for values greater than or equal to 1. Values below 1 return NaN.

$acosh: 10 (valid edge case)
$acosh: 21.317 (valid)
$acosh: 0.5NaN (out of range!)

⚡ Quick Reference

QuestionAnswer
Operator typeAggregation expression operator (hyperbolic)
Syntax{ $acosh: <expression> }
Input range≥ 1
Inverse of$cosh
Common stages$project, $addFields, $set
Edge case
{
  $acosh: 1
}

Returns 0

Field
{
  $acosh: "$x"
}

From document field

Example
{
  $acosh: 2
}

≈ 1.317

Null input
{
  $acosh: null
}

Returns null

Examples Gallery

Walk through sample data, run an aggregation pipeline, and inspect the inverse hyperbolic cosine results.

📚 Basic Computation

Use a values collection and compute $acosh for each numeric field with $project.

Sample Input Documents

Suppose you have a values collection with a numeric field x:

mongosh
[
  { "_id": ObjectId("609c26812e9274a86871bc6a"), "x": 1 },
  { "_id": ObjectId("609c26812e9274a86871bc6b"), "x": 2 },
  { "_id": ObjectId("609c26812e9274a86871bc6c"), "x": 3 }
]

Example 1 — Basic $acosh on a Field

Compute the inverse hyperbolic cosine for each value:

mongosh
db.values.aggregate([
  {
    $project: {
      acoshValue: { $acosh: "$x" }
    }
  }
])

How It Works

  • Document 1: x is 1acosh(1) = 0.
  • Document 2: x is 2acosh(2)1.317.
  • Document 3: x is 3acosh(3)1.763.

📈 Practical Patterns

Apply $acosh in growth modeling and validate results with rounding.

Example 2 — Growth Rate from Hyperbolic Data

When a field stores a hyperbolic cosine result, recover the original scale factor:

mongosh
db.growth.aggregate([
  {
    $project: {
      label: 1,
      coshResult: 1,
      scaleFactor: { $acosh: "$coshResult" },
      scaleFactorRounded: {
        $round: [ { $acosh: "$coshResult" }, 3 ]
      }
    }
  }
])

How It Works

If a prior pipeline stage computed $cosh(t), applying $acosh on that result recovers t (when the value is ≥ 1). Use $round for cleaner display values.

Example 3 — Guard Against Invalid Inputs

Only compute $acosh when the value is at least 1; otherwise return null:

mongosh
db.values.aggregate([
  {
    $project: {
      x: 1,
      acoshValue: {
        $cond: [
          { $gte: [ "$x", 1 ] },
          { $acosh: "$x" },
          null
        ]
      }
    }
  }
])

How It Works

Wrapping $acosh in $cond prevents NaN results when your data may contain values below 1.

Example 4 — $acosh with Literal Values

Common boundary values every beginner should know:

mongosh
db.samples.aggregate([
  {
    $project: {
      acoshOne:  { $acosh: 1 },     // 0
      acoshTwo:  { $acosh: 2 },     // ≈ 1.317
      acoshTen:  { $acosh: 10 }     // ≈ 2.993
    }
  }
])

How It Works

$acosh(1) = 0 is the most important edge case. Larger inputs produce progressively larger results, growing slowly compared to exponential functions.

🚀 Use Cases

  • Growth analysis — model exponential growth rates or processes with logarithmic-style scaling.
  • Financial modeling — transform hyperbolic values in interest-rate or asset-value calculations.
  • Statistical analysis — normalize skewed distributions or transform extreme values in analytics pipelines.
  • Signal processing — recover parameters from hyperbolic cosine outputs in scientific datasets.

🧠 How $acosh Works

1

MongoDB reads the value

The pipeline evaluates the input — a field like "$x" or a numeric expression.

Input
2

Domain check (≥ 1)

If the value is below 1, MongoDB returns NaN. Valid inputs proceed to the calculation.

Validate
3

$acosh computes the inverse

MongoDB applies the inverse hyperbolic cosine and stores the result in your projected field.

Transform
=

Hyperbolic value recovered

You get a numeric result ready for further math, grouping, or reporting.

Conclusion

The $acosh operator is a specialized but powerful math tool in MongoDB aggregation pipelines. It reverses hyperbolic cosine values and supports growth modeling, financial analysis, and statistical transformations.

For beginners, remember three things: input must be ≥ 1, acosh(1) = 0, and values below 1 return NaN. Use $cond to guard against invalid inputs in real-world data.

💡 Best Practices

✅ Do

  • Validate that input values are ≥ 1 before applying $acosh
  • Remember acosh(1) = 0 when checking results
  • Use $round for readable output values
  • Pair with $cosh to verify round-trip calculations
  • Handle null inputs with $ifNull when needed

❌ Don’t

  • Pass values less than 1 without guarding against NaN
  • Confuse $acosh with $acos (different functions)
  • Use $acosh as a query filter operator outside expressions
  • Assume it works on negative numbers (returns NaN)
  • Forget to test the edge case where input equals exactly 1

Key Takeaways

Knowledge Unlocked

Five things to remember about $acosh

Use these points when working with hyperbolic math in MongoDB.

5
Core concepts
📝 02

Simple Syntax

{ $acosh: expr }

Syntax
📏 03

Input Range

Must be ≥ 1.

Domain
🔢 04

Edge Case

acosh(1) = 0

Special
05

Below 1

Returns NaN.

Edge case

❓ Frequently Asked Questions

$acosh returns the inverse hyperbolic cosine (arc hyperbolic cosine) of a number. It is the reverse of $cosh and is used in aggregation expression stages like $project and $addFields.
The syntax is { $acosh: <expression> }. The expression can be a field reference like "$x", a literal number, or another numeric expression.
$acosh is defined for values greater than or equal to 1. Values less than 1 return NaN.
acosh(1) equals 0. This is an important edge case when validating pipeline results.
$acosh returns null when the input is null. It does not throw an error.

Continue the Math Operator Series

Move on to $add or review $acos for arc cosine calculations.

Next: $add →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

5 people found this page helpful