MongoDB $acosh Operator

Beginner
5 min read
Updated: Oct 2026
3 examples
Live preview

What Is $acosh?

$acosh is a MongoDB aggregation expression that returns the inverse hyperbolic cosine of a number—the value whose hyperbolic cosine equals that input. Results are in radians. Input must be 1 or greater.

Remember
$acosh = Math.acosh for aggregation

{ $acosh: <expression> }

input  → must be ≥ 1
output → radians (≥ 0)
degrees → wrap with $radiansToDegrees

acosh(1) → 0
null / missing → null
x < 1 → pipeline error
UsePrefer
Inverse hyperbolic cosine$acosh
Hyperbolic cosine (forward)$cosh
Radians → degrees$radiansToDegrees
Regular inverse cosine$acos

How to Use $acosh in MongoDB

Pass a number ≥ 1, then convert units if you need degrees.

  1. Choose an expression stage ($addFields or $project).
  2. Ensure the argument is ≥ 1 (filter or validate first if data can be smaller).
  3. Pass that expression to $acosh to get radians.
  4. Optionally wrap with $radiansToDegrees for a degree result.
PieceRequired?Role
$acoshYesInverse hyperbolic cosine → radians
ExpressionYesNumber ≥ 1, field, or nested math
$radiansToDegreesNoConvert output when you want degrees

Pseudocode

Pseudocode
for each document:
    x = evaluate(expression)
    if x is null or missing:
        result = null
    else if x is NaN:
        result = NaN
    else if x is +Infinity:
        result = Infinity
    else if x < 1:
        error  // aggregation fails
    else:
        result = acosh(x)   // radians
    emit { ..., field: result }

Cheat Sheet

Keep these facts handy while writing inverse hyperbolic cosine expressions.

TopicDetail
TypeAggregation expression (not a find filter)
Syntax{ $acosh: <expression> }
Domainx ≥ 1 (up to +Infinity)
Range0 to +Infinity radians
Degrees pattern{ $radiansToDegrees: { $acosh: "$x" } }
Sample checkacosh(1) = 0; acosh(3) ≈ 100.998°

Live Preview

Watch $acosh turn an x value into radians (and degrees). Try values ≥ 1.

Simulates $acosh then $radiansToDegrees (same idea as the mongosh examples below).

Result
x = 3
$acosh(x) → 1.762747 rad
$radiansToDegrees → 100.997973 °

{ y_rad: 1.762747, y_deg: 100.997973 }

Worked Walkthrough — acosh(3)

One number on the x-axis: 3. Inverse hyperbolic cosine gives a y-value in radians; convert if you want degrees.

Calculation
Document:
  { _id: 2, x: 3 }

$acosh("$x")
  acosh(3) ≈ 1.762747 radians

$radiansToDegrees(...)
  ≈ 100.997973 degrees

Check:
  acosh(1) = 0
  cosh(acosh(3)) ≈ 3 ✓

MongoDB Examples

We store three x values (≥ 1). First we compute $acosh in radians, then convert to degrees. Run these in mongosh after inserting the sample data once.

Example 1 — Sample Data

Imagine three numbers on a number line: 1, 3, and 10. All are valid for $acosh because each is ≥ 1. We save them in a collection named hyperbolic.

mongosh
db.hyperbolic.insertMany([
  { _id: 1, x: 1 },
  { _id: 2, x: 3 },
  { _id: 3, x: 10 }
]);

How the Data Is Stored in MongoDB

After the insert, MongoDB keeps three documents in hyperbolic. Run find() to see them:

mongosh
db.hyperbolic.find().sort({ _id: 1 })

Read each document like this:

Field in MongoDBValuePlain English
_id1, 2, 3Document id (row number for this lesson)
x1, 3, 10Input number for $acosh (must be ≥ 1)
Picture
Number line (only x ≥ 1 is allowed):

  ... 0 ... 1 -------- 3 -------------- 10 ...
            ↑          ↑                 ↑
         acosh=0    ~1.76 rad         ~2.99 rad

Invalid for $acosh: 0, 0.5, -1  → pipeline error

How It Works

  1. Insert once. insertMany adds three documents to hyperbolic.
  2. MongoDB stores fields as written. Each document has _id and x—plain numbers.
  3. find() shows the same shape. What you inserted is what you get back—ready for $acosh in the next examples.

Example 2 — Result in Radians

Goal: for each stored x, compute $acosh in radians.

mongosh
db.hyperbolic.aggregate([
  {
    $addFields: {
      y_rad: { $acosh: "$x" }
    }
  }
]);

How It Works

  1. Read the stored x. MongoDB already has 1, 3, and 10 from Example 1.
  2. Apply $acosh. { $acosh: "$x" } computes inverse hyperbolic cosine for each document.
  3. Edge case check. acosh(1) is exactly 0.
  4. Keep all fields. $addFields adds y_rad next to the original x—nothing is deleted.

Example 3 — Result in Degrees

Same data, but wrap $acosh with $radiansToDegrees for a more familiar unit.

mongosh
db.hyperbolic.aggregate([
  {
    $addFields: {
      y_deg: {
        $radiansToDegrees: {
          $acosh: "$x"
        }
      }
    }
  }
]);

How It Works

  1. Same stored documents. Still using x values 1, 3, and 10.
  2. $acosh first. Inverse hyperbolic cosine yields radians.
  3. Convert units. $radiansToDegrees turns those into degrees (about 101° for x = 3).
  4. Easy check. x = 1 still maps to 0°.

Edge Cases & Pitfalls

Check these before using $acosh in production pipelines.

domain

Stay at x ≥ 1

Values below 1 make the pipeline fail. Filter with $match or clamp before calling $acosh.

units

Output is radians

Do not treat the raw result as degrees. Convert with $radiansToDegrees when your report expects °.

null

Null and missing become null

Missing fields return null, not an error. Handle them before hyperbolic math if nulls are invalid in your data.

vs acos

Not the same as $acos

$acos is regular inverse cosine (domain [-1, 1]). $acosh is hyperbolic (domain ≥ 1).

Performance Notes

ApproachCostBest for
$acosh alonePer-document mathValues already ≥ 1
$match then $acoshFilter + mathDirty data that may be < 1
+ $radiansToDegreesOne extra conversionHuman-readable degree reports

Hyperbolic expressions are cheap compared with large sorts or joins. Filter early with $match when only some documents need the transform.

Key Takeaways

  • Role: inverse hyperbolic cosine → result in radians.
  • Domain: argument must be ≥ 1.
  • Degrees: wrap with $radiansToDegrees.
  • Check: acosh(1) = 0.

One line: $acosh answers “which value has this hyperbolic cosine?”—in radians, for inputs ≥ 1.

Frequently Asked Questions

$acosh returns the inverse hyperbolic cosine (hyperbolic arc cosine) of a number—the value whose hyperbolic cosine is that number. Results are in radians. Use it inside aggregation expression stages such as $project and $addFields.
The argument must resolve to a number greater than or equal to 1 (up to +Infinity). Values less than 1 cause the aggregation to fail with an error.
$acosh returns radians. Convert with $radiansToDegrees when you want degrees.
acosh(1) equals 0. That is a useful check when testing a pipeline.
$acosh returns null when the input is null or the field is missing. If the argument is NaN, $acosh returns NaN. Infinity returns Infinity.
Yes for the math. Think of $acosh as MongoDB’s aggregation version of Math.acosh—run it in the pipeline, not as a standalone find() filter.

Next: $add

Add numbers together, or add milliseconds to a date.

$add tutorial →

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.

9 people found this page helpful