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.
Fundamentals
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.
Foundation
📝 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.5 → 0.524 rad (valid, 30°)
$asin: 1 → 1.571 rad (valid, 90°)
$asin: 1.2 → null(out of range!)
Cheat Sheet
⚡ Quick Reference
Question
Answer
Operator type
Aggregation expression operator (trigonometry)
Syntax
{ $asin: <expression> }
Input range
-1 to 1 (inclusive)
Output unit
Radians (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
Hands-On
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):
$asin(0) = 0, $asin(1) = π/2, and $asin(-1) = -π/2. These edge cases help validate pipeline logic.
Applications
🚀 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.
Wrap Up
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.