The $radiansToDegrees operator converts an angle from radians to degrees in MongoDB aggregation pipelines. Use it when math stages produce radians but you need readable degree values for dashboards, APIs, or reports.
01
Radians → Degrees
Convert angle units in pipelines.
02
Syntax
One expression inside $radiansToDegrees.
03
Display Ready
Human-readable angle output.
04
Formula
radians × (180 / π).
05
Use Cases
Geospatial, sensors, reports.
06
Inverse
Pair with $degreesToRadians.
Fundamentals
Definition and Usage
In MongoDB’s aggregation framework, the $radiansToDegrees operator converts a numeric radian value into degrees. For example, π radians becomes 180 degrees, and π/2 radians becomes 90 degrees. This is the inverse of $degreesToRadians and is essential when trig operators like $asin or $acos return radians that users expect to see in degrees.
💡
Beginner Tip
Think of $radiansToDegrees as the “display” step after math. MongoDB trig functions work in radians internally; convert back to degrees before showing angles on a map, chart, or API response.
Foundation
📝 Syntax
The $radiansToDegrees operator takes one numeric expression (an angle in radians):
mongosh
{ $radiansToDegrees: <expression> }
Syntax Rules
$radiansToDegrees — multiplies the input by 180/π and returns degrees.
<expression> — can be a field path ("$bearingRad"), a literal number, or another numeric expression.
Use it inside stages like $project, $addFields, or $set.
If the input is null, the result is null.
Negative radian values convert to negative degrees (valid for direction or rotation).
📐 Conversion Formula: radians × (180 / π)
MongoDB applies the standard math formula. Common radian values convert predictably:
$radiansToDegrees: π (≈ 3.142) → 180°
$radiansToDegrees: π/2 (≈ 1.571) → 90°
$radiansToDegrees: 2π (≈ 6.283) → 360°
Cheat Sheet
⚡ Quick Reference
Question
Answer
Operator type
Aggregation expression operator (math / unit conversion)
Syntax
{ $radiansToDegrees: <expression> }
Input
Angle in radians (any numeric value)
Output unit
Degrees
Inverse operator
$degreesToRadians
Example
{
$radiansToDegrees: 3.14159
}
≈ 180° (π rad)
Field
{
$radiansToDegrees: "$bearingRad"
}
Convert stored radians
Right angle
{
$radiansToDegrees: 1.5708
}
≈ 90° (π/2 rad)
Null input
{
$radiansToDegrees: null
}
Returns null
Hands-On
Examples Gallery
Start with angles stored in radians, convert them to degrees for display, and chain with inverse trig operators.
📚 Radian to Degree Conversion
Use a locations collection with bearings in radians and convert them to degrees with $project.
Sample Input Documents
Suppose you have a locations collection where each document stores a bearing in radians:
$degreesToRadians followed by $radiansToDegrees reconstructs the original degree value. The two operators are mathematical inverses.
Applications
🚀 Use Cases
API and dashboard output — convert pipeline radian results to degrees for end users.
Inverse trig results — display $acos, $asin, or $atan output in degrees.
Geospatial reporting — transform computed bearings from radians into compass-friendly degrees.
Data validation — round-trip with $degreesToRadians to verify angle conversions in ETL pipelines.
🧠 How $radiansToDegrees Works
1
MongoDB reads the radian value
The pipeline evaluates the input — a field like "$bearingRad" or a numeric literal such as 3.14159.
Input
2
$radiansToDegrees applies the formula
MongoDB multiplies the value by 180/π to produce the equivalent angle in degrees.
Transform
3
The result is stored in the pipeline
The degree value is written to the field you define in $project or $addFields.
Output
=
📐
Degrees ready for display
Human-readable angles for maps, charts, APIs, and operator dashboards.
Wrap Up
Conclusion
The $radiansToDegrees operator converts radian angles to degrees in MongoDB aggregation pipelines. It is the display counterpart to $degreesToRadians and is essential when trig math produces radians but users expect degree values.
For beginners, the key idea is simple: wrap any radian expression in { $radiansToDegrees: ... } inside a stage like $project, and MongoDB returns the degree equivalent using the standard 180/π formula. Next in the series: $rand.
Use $radiansToDegrees after $acos, $asin, or $atan for display
Keep radian fields when precision math is needed downstream
Test with 0, π/2, π, and 2π to validate pipeline logic
Pair with $degreesToRadians for round-trip conversions
Handle null inputs with $ifNull when needed
❌ Don’t
Assume trig output is already in degrees
Mix up $radiansToDegrees with $degreesToRadians
Use $radiansToDegrees as a query filter outside expressions
Forget that null input returns null
Pass degree values into $radiansToDegrees by mistake
Summary
Key Takeaways
Knowledge Unlocked
Five things to remember about $radiansToDegrees
Use these points when converting angles in MongoDB pipelines.
5
Core concepts
📐01
Radians to Degrees
Multiply by 180/π.
Purpose
📝02
Simple Syntax
{ $radiansToDegrees: expr }
Syntax
🛠03
Display Output
After inverse trig ops.
Usage
🌎04
Inverse Pair
$degreesToRadians.
Pairing
⚠05
Null Aware
null in → null out.
Edge case
❓ Frequently Asked Questions
$radiansToDegrees converts an angle from radians to degrees. Use it when pipeline math produces radians but you need human-readable degree values for display, reports, or APIs.
The syntax is { $radiansToDegrees: <expression> }. The expression can be a field reference like "$bearingRad", a literal number such as 3.14159, or another numeric expression.
MongoDB applies degrees = radians × (180 / π). For example, π radians becomes 180 degrees, and π/2 radians becomes 90 degrees.
$degreesToRadians converts degrees to radians. The two operators are inverses: one multiplies by π/180, the other multiplies by 180/π.
$radiansToDegrees returns null when the input is null. It does not throw an error.