$degreesToRadians (Degrees to Radians)
Last updated: 2026-10-09
$degreesToRadians (Degrees to Radians)
$degreesToRadians converts degrees to radians by multiplying by π/180. Since the trigonometric operators $sin, $cos, and $tan take radians as input, converting angles first avoids hand-multiplying by pi. It is used in geographic coordinates and trigonometry. A null or missing argument yields null, and NaN input returns NaN. It is the inverse of $radiansToDegrees. Note that very large inputs can lose precision.
| Category | Math |
|---|---|
| MongoDB Version | 1.0+ |
| Example Language | mongosh (Shell) |
📝 Syntax
{ $degreesToRadians: <numeric-expression> }
⚙️ Parameters
| degrees | A numeric expression in degrees. |
|---|
Returns:The radians equivalent of the input; null when null or missing
▶ Example
Run the commands below in your local mongosh (requires a running mongod):
// $degreesToRadians: convert degrees to radians
db.trig.aggregate([
{ $project: {
rad: { $degreesToRadians: '$deg' }
} }
])
Output:
{ '_id': 1, 'rad': 3.141592653589793 }
{ '_id': 2, 'rad': 0.5235987755982988 }
📌 Notes
- Equivalent to multiplying by π/180
- Feed $sin, $cos, and $tan in radians by converting first
- Inverse of $radiansToDegrees
🏷️ Related Tags
💡 Related Cases
More hands-on cases coming soon.
📚 Related Tutorials
❓ FAQ
QWhat is the formula for $degreesToRadians?
AMultiply the input by π and divide by 180; 180 degrees is about 3.1416 radians.
QWhy convert to radians before trigonometry?
A$sin, $cos, and $tan expect radians, so passing degrees gives wrong results.
QWhat is $degreesToRadians(90)?
AIt is π/2, about 1.5708 radians.