MongoDB $sinh Operator

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

What Is $sinh?

$sinh is a MongoDB aggregation expression that returns the hyperbolic sine of a number: (ex − e−x) / 2. Inputs are treated as radians. Unlike $sin, the result is not limited to −1…1 and is not periodic.

Remember
$sinh = Math.sinh for aggregation

{ $sinh: <expression> }

sinh(x) = (e^x − e^(-x)) / 2

$sinh(0)  → 0
$sinh(1)  → ≈ 1.175
$sinh(-1) → ≈ -1.175   // odd: sinh(-x) = -sinh(x)

null / missing → null
degrees → convert with $degreesToRadians first
UsePrefer
Hyperbolic sine$sinh
Circular sine$sin
Inverse hyperbolic sine$asinh

How to Use $sinh in MongoDB

Pass a numeric expression in radians (convert degrees if needed).

  1. Choose an expression stage ($addFields or $project).
  2. Provide a number, field, or nested math as the argument.
  3. If the value is in degrees, wrap with $degreesToRadians first.
  4. Pass that expression to $sinh.
PieceRequired?Role
$sinhYesHyperbolic sine
ExpressionYesNumeric input (radians)
$degreesToRadiansNoConvert degree inputs

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:
        result = (e^x - e^(-x)) / 2
    emit { ..., field: result }

Cheat Sheet

Keep these facts handy while writing hyperbolic-sine expressions.

TopicDetail
TypeAggregation expression (not a find filter)
Syntax{ $sinh: <expression> }
Formula(ex − e−x) / 2
UnitsInput treated as radians
Oddnesssinh(−x) = −sinh(x)
Key valuessinh(0)=0, sinh(1)≈1.175
vs $sinHyperbolic vs circular

Live Preview

Watch $sinh compute hyperbolic sine. Try common radian inputs.

Simulates $sinh (same idea as the mongosh examples below).

Result
x = 1
$sinh(x) → 1.175201

{ result: 1.175201 }

Worked Walkthrough — sinh(1)

Compute hyperbolic sine of 1 using the definition with e.

Calculation
x = 1

e^1  ≈ 2.71828
e^-1 ≈ 0.36788

sinh(1) = (e^1 − e^-1) / 2
        ≈ (2.71828 − 0.36788) / 2
        ≈ 2.35040 / 2
        ≈ 1.17520

$sinh(1) → ≈ 1.175201

Check: sinh(-1) ≈ -1.175201 (odd function) ✓

MongoDB Examples

We use a small hyperbola collection of radian values, then show a degrees conversion. Run these in mongosh after inserting the sample data once.

Example 1 — Sample Data

Imagine three numbers stored as radians: 0, 1, and -1. We save them in hyperbola.

mongosh
db.hyperbola.insertMany([
  { _id: 1, x: 0 },
  { _id: 2, x: 1 },
  { _id: 3, x: -1 }
]);

How the Data Is Stored in MongoDB

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

mongosh
db.hyperbola.find()

Read one document like this:

Field in MongoDBValue (doc 2)Plain English
_id2Document id
x1Input in radians

How It Works

  1. Insert once. insertMany adds three documents to hyperbola.
  2. x is in radians. That is what $sinh expects by default.
  3. find() shows the same shape. Ready for $sinh next.

Example 2 — $sinh in Radians

Goal: compute hyperbolic sine for each stored x.

mongosh
db.hyperbola.aggregate([
  {
    $addFields: {
      sinh_x: { $sinh: "$x" }
    }
  }
]);

How It Works

  1. Read x. Document 2 has x: 1.
  2. Apply $sinh. $sinh("$x") → about 1.175.
  3. Odd function check. Document 3 returns the negative of document 2.
  4. $addFields keeps originals. x stays; sinh_x is added.

Example 3 — Degrees → $sinh

If your angle is stored in degrees, convert to radians first, then call $sinh.

mongosh
db.trigonometry.insertOne({
  _id: 1,
  angle: 53.13010235415598
});

db.trigonometry.aggregate([
  {
    $addFields: {
      sinh_output: {
        $sinh: { $degreesToRadians: "$angle" }
      }
    }
  }
]);

How It Works

  1. Store degrees. angle is about 53.13°, not radians.
  2. Convert units. $degreesToRadians turns degrees into radians.
  3. Then $sinh. Hyperbolic sine runs on the radian value → about 1.066.
  4. Skip conversion only when the field is already in radians.

Edge Cases & Pitfalls

Check these before using $sinh in production pipelines.

units

Radians by default

Do not feed raw degrees into $sinh. Convert with $degreesToRadians first.

vs

Not the same as $sin

$sin is circular and bounded. $sinh grows quickly for large |x|.

null

Null and missing become null

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

range

Large |x| grows fast

Hyperbolic sine rises exponentially. Very large inputs can overflow toward ±Infinity.

Performance Notes

ApproachCostBest for
$sinh alonePer-document mathValues already in radians
+ $degreesToRadiansOne extra conversionDegree-stored angles
With other hyperbolicsStill O(docs)sinh / cosh / tanh reports

Hyperbolic math is cheap compared with large sorts or joins. Filter early with $match when only some documents need $sinh.

Key Takeaways

  • Role: hyperbolic sine of x (radians).
  • Formula: (ex − e−x) / 2.
  • Odd: sinh(−x) = −sinh(x).
  • Degrees: convert with $degreesToRadians.

One line: $sinh answers “what is the hyperbolic sine of this radian value?”—like Math.sinh.

Frequently Asked Questions

$sinh returns the hyperbolic sine of a number. The formula is sinh(x) = (e^x − e^(−x)) / 2. Use it inside aggregation expression stages such as $project and $addFields. Inputs are treated as radians.
The syntax is { $sinh: <expression> }. The expression can be a field reference, a literal number, or nested numeric math.
$sin is circular trigonometry (periodic, output roughly −1 to 1). $sinh is hyperbolic: it grows exponentially and is not periodic. They solve different problems.
Yes. sinh(−x) = −sinh(x). Applying $sinh to a negative value returns the negated result of the positive value.
$sinh returns null when the input is null or the field is missing. NaN returns NaN. ±Infinity returns ±Infinity.
Convert degrees to radians first with $degreesToRadians, then pass that to $sinh: { $sinh: { $degreesToRadians: "$angle" } }.

Next: $size

Return how many elements an array field contains.

$size tutorial →

CODETOFUN NEWS

Stay Ahead in Tech

Get the latest IT news, programming updates, and technology trends directly on your phone.

Your daily dose of tech, straight to your feed.

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