$asin is a MongoDB aggregation expression that returns the inverse sine (arc sine) of a number—the angle whose sine equals that value. Results are in radians. Input must be between -1 and 1 inclusive.
Remember
$asin = Math.asin for aggregation
{ $asin: <expression> }
input → must be in [-1, 1]
output → radians (-π/2 … π/2)
degrees → wrap with $radiansToDegrees
null / missing → null
outside [-1, 1] → pipeline error
Ensure the argument is in [-1, 1] (often opposite / hypotenuse via $divide).
Pass that expression to $asin to get radians.
Optionally wrap with $radiansToDegrees for a degree result.
Piece
Required?
Role
$asin
Yes
Inverse sine → radians
Expression
Yes
Number in [-1, 1], field, or nested math
$radiansToDegrees
No
Convert 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 < -1 or x > 1:
error // aggregation fails
else:
result = asin(x) // radians
emit { ..., field: result }
Reference
Cheat Sheet
Keep these facts handy while writing inverse-sine expressions.
Topic
Detail
Type
Aggregation expression (not a find filter)
Syntax
{ $asin: <expression> }
Domain
-1 ≤ x ≤ 1
Range
-π/2 to π/2 radians
Degrees pattern
{ $radiansToDegrees: { $asin: <x> } }
Triangle pattern
$asin({ $divide: [opposite, hypotenuse] })
Sample check
3-4-5 triangle: asin(3/5) ≈ 36.87°
Try it
Live Preview
Watch $asin turn a sine value into radians (and degrees). Try values in [-1, 1].
Simulates $asin then $radiansToDegrees (same idea as the mongosh examples below).
Result
x = 0.6
$asin(x) → 0.643501 rad
$radiansToDegrees → 36.869898 °
{ angle_rad: 0.643501, angle_deg: 36.869898 }
Trace
Worked Walkthrough — 3-4-5 Triangle
Right triangle with sides 3, 4, and 5. Angle A is opposite side_a (3), so sine of A = opposite / hypotenuse = 3 / 5.
Easy check. In a 3-4-5 triangle, the smaller acute angle is about 37°—so 36.87° looks right (same as $acos(4/5)).
Edge Cases & Pitfalls
Check these before using $asin in production pipelines.
domain
Stay inside [-1, 1]
Values outside the domain make the pipeline fail. Clamp or validate ratios before calling $asin.
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 trig if nulls are invalid in your data.
hyp
Avoid divide-by-zero
Triangle ratios need a non-zero hypotenuse. Guard with $cond or filter bad rows first.
Analysis
Performance Notes
Approach
Cost
Best for
$asin alone
Per-document math
Angles already stored as sines
$divide + $asin
Still O(docs)
Right-triangle angles from sides
+ $radiansToDegrees
One extra conversion
Human-readable degree reports
Trig expressions are cheap compared with large sorts or joins. Filter early with $match when only some documents need an angle.
Remember
Key Takeaways
Role: inverse sine → angle in radians.
Domain: argument must be in [-1, 1].
Degrees: wrap with $radiansToDegrees.
Triangles:$asin(opposite / hypotenuse).
One line:$asin answers “which angle has this sine?”—in radians, for inputs between -1 and 1.
Frequently Asked Questions
$asin returns the inverse sine (arc sine) of a number—the angle whose sine 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 between -1 and 1 inclusive. Values outside that range cause the aggregation to fail with an error.
$asin returns radians. Convert with $radiansToDegrees, or multiply by 180/π using $multiply and $divide.
$asin returns null when the input is null or the field is missing. If the argument is NaN, $asin returns NaN.
Sine equals opposite / hypotenuse. Divide those sides, then pass the ratio to $asin. Wrap with $radiansToDegrees if you want degrees.
Yes for the math. Think of $asin as MongoDB’s aggregation version of Math.asin—run it in the pipeline, not as a standalone find() filter.