MongoDB $asin Operator

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

What You’ll Learn

The $asin operator returns the arc sine (inverse sine) of a number in MongoDB aggregation pipelines. If you know a sine value, $asin tells you the angle in radians.

01

Inverse Sine

Sine value → angle.

02

Syntax

One expression inside $asin.

03

Radians

Output is always in radians.

04

Input Range

Values must be -1 to 1.

05

Use Cases

Geometry, robotics, signals.

06

Degrees

Convert with $multiply/$divide.

Definition and Usage

In MongoDB’s aggregation framework, the $asin operator computes the arc sine of a numeric expression. For example, if sin(30°) = 0.5, then $asin(0.5) returns approximately 0.524 radians (which is 30°). The input is a sine ratio, not an angle — and the output is the angle in radians.

💡
Beginner Tip

Think of $asin as the reverse of $sin. Use it inside aggregation expression stages like $project or $addFields, not as a standalone query filter.

📝 Syntax

The $asin operator takes one numeric expression:

mongosh
{ $asin: <expression> }

Syntax Rules

  • $asin — returns the arc sine of the expression in radians.
  • <expression> — must evaluate to a number between -1 and 1 (inclusive).
  • Use it inside stages like $project, $addFields, or $set.
  • If the input is null, the result is null.
  • Values outside [-1, 1] return null or NaN.

⚠️ Valid Input Range: -1 to 1

$asin only accepts sine values in the range -1 to 1. Anything outside that range returns null or NaN.

$asin: 0.50.524 rad (valid, 30°)
$asin: 11.571 rad (valid, 90°)
$asin: 1.2null (out of range!)

⚡ Quick Reference

QuestionAnswer
Operator typeAggregation expression operator (trigonometry)
Syntax{ $asin: <expression> }
Input range-1 to 1 (inclusive)
Output unitRadians (range -π/2 to π/2)
Common stages$project, $addFields, $set
Example
{
  $asin: 0.5
}

≈ 0.524 rad (30°)

Field
{
  $asin: "$sine"
}

Angle from sine field

Edge case
{
  $asin: 0
}

Returns 0 radians

Null input
{
  $asin: null
}

Returns null

Examples Gallery

Start with sine values, run an aggregation pipeline, and see the resulting angles in radians.

📚 Sine to Angle

Use an angles collection with stored sine values and recover the angle in radians with $project.

Sample Input Documents

Suppose you have an angles collection where each document stores a sine value (not an angle):

mongosh
[
  { "_id": ObjectId("609c26812e9274a86871bc6a"), "sine": 0.5 },
  { "_id": ObjectId("609c26812e9274a86871bc6b"), "sine": 0.8 },
  { "_id": ObjectId("609c26812e9274a86871bc6c"), "sine": 1.2 }
]

Example 1 — Basic $asin on a Field

Compute the angle in radians for each sine value:

mongosh
db.angles.aggregate([
  {
    $project: {
      sine: 1,
      angleRadians: { $asin: "$sine" }
    }
  }
])

How It Works

  • Document 1: sine is 0.5asin(0.5)0.524 rad (30°).
  • Document 2: sine is 0.8asin(0.8)0.927 rad.
  • Document 3: sine is 1.2 → out of range, returns null.

📈 Practical Patterns

Convert radians to degrees and handle common trigonometric edge cases in pipelines.

Example 2 — Convert Radians to Degrees

MongoDB returns radians by default. Multiply by 180 / π to get degrees:

mongosh
db.angles.aggregate([
  {
    $project: {
      sine: 1,
      angleRadians: { $asin: "$sine" },
      angleDegrees: {
        $multiply: [
          { $asin: "$sine" },
          { $divide: [ 180, 3.141592653589793 ] }
        ]
      }
    }
  }
])

How It Works

The formula is degrees = radians × (180 / π). Use $multiply and $divide to apply it inside the pipeline.

Example 3 — Angle from a Unit Vector’s y-Component

When you have x/y components of a unit vector, compute the angle from the y-axis using the sine value:

mongosh
db.vectors.aggregate([
  {
    $project: {
      label: 1,
      x: 1,
      y: 1,
      angleFromYAxis: { $asin: "$y" }
    }
  }
])

How It Works

For a unit vector, the y-component equals sin(θ). Applying $asin on $y recovers the angle from the horizontal axis in radians.

Example 4 — $asin with Literal Values

Common boundary values every beginner should know:

mongosh
db.samples.aggregate([
  {
    $project: {
      asinZero:  { $asin: 0 },     // 0 rad (0°)
      asinHalf:  { $asin: 0.5 },   // ≈ 0.524 rad (30°)
      asinOne:   { $asin: 1 },     // ≈ 1.571 rad (90°)
      asinNeg:   { $asin: -1 }     // ≈ -1.571 rad (-90°)
    }
  }
])

How It Works

$asin(0) = 0, $asin(1) = π/2, and $asin(-1) = -π/2. These edge cases help validate pipeline logic.

🚀 Use Cases

  • Angle conversion — recover angles from sine ratios in geometric or vector data.
  • Trigonometric analysis — transform stored trig values for signal processing or visualization.
  • Robotics and engineering — calculate joint angles from sine components in sensor readings.
  • Data visualization — convert sine-based measurements into radians or degrees for charts.

🧠 How $asin Works

1

MongoDB reads the sine value

The pipeline evaluates the input — a field like "$sine" or a numeric expression between -1 and 1.

Input
2

$asin computes the inverse

MongoDB applies the arc sine function and returns the angle in radians ( -π/2 to π/2 ).

Transform
3

The result is stored in the pipeline

The angle is written to the field you define in $project or $addFields.

Output
=

Angle recovered from data

Use the radians directly or convert to degrees for reports and dashboards.

Conclusion

The $asin operator is a practical trigonometry tool in MongoDB aggregation pipelines. It converts sine values back into angles, which is essential for geometry, engineering, robotics, and any dataset that stores trig ratios instead of raw angles.

For beginners, remember three things: input must be between -1 and 1, output is in radians, and values outside the valid range return null.

💡 Best Practices

✅ Do

  • Validate that input values are between -1 and 1
  • Remember output is in radians, not degrees
  • Use $round when displaying angle results
  • Pair with $sin to verify round-trip calculations
  • Handle null inputs with $ifNull when needed

❌ Don’t

  • Pass angle values into $asin — it expects a sine ratio
  • Pass values outside the -1 to 1 range without guarding
  • Assume output is in degrees
  • Confuse $asin (inverse sine) with $sin (sine)
  • Use $asin as a query filter outside expressions

Key Takeaways

Knowledge Unlocked

Five things to remember about $asin

Use these points when working with trigonometric data in MongoDB.

5
Core concepts
📝 02

Simple Syntax

{ $asin: expr }

Syntax
📏 03

Input Range

-1 to 1 only.

Domain
🛠 04

Radians Output

Convert to degrees if needed.

Units
05

Out of Range

Values > 1 return null.

Edge case

❓ Frequently Asked Questions

$asin returns the arc sine (inverse sine) of a number. It answers the question: which angle has this sine value? The result is always in radians.
The syntax is { $asin: <expression> }. The expression can be a field reference like "$sine", a literal number, or another numeric expression.
$asin only works for values between -1 and 1 inclusive. Values outside that range return null or NaN.
$asin returns radians. To convert to degrees, multiply the result by 180 and divide by pi using $multiply and $divide.
$asin returns null when the input is null. It does not throw an error.

Continue the Math Operator Series

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

Next: $asinh →

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