$acos (Arccosine)
Last updated: 2026-10-09
$acos (Arccosine)
$acos returns the arccosine of a number, with the result in radians and the input restricted to -1 through 1. It is used to recover an angle from a cosine value or to compute the angle between two vectors. A null or missing argument yields null; input outside [-1, 1] throws an error. Convert the radian result to degrees with $radiansToDegrees. As the inverse of $cos it returns values from 0 to π radians (0 to 180 degrees).
| Category | Math |
|---|---|
| MongoDB Version | 1.0+ |
| Example Language | mongosh (Shell) |
📝 Syntax
{ $acos: <numeric-expression> }
⚙️ Parameters
| numeric value | A numeric expression between -1 and 1. |
|---|
Returns:The arccosine in radians; null when null or missing, error outside [-1, 1]
▶ Example
Run the commands below in your local mongosh (requires a running mongod):
// $acos: angle (radians) from a cosine value
db.trig.aggregate([
{ $project: {
angle: { $acos: '$cosValue' }
} }
])
Output:
{ '_id': 1, 'angle': 0 }
{ '_id': 2, 'angle': 1.0471975511965979 }
📌 Notes
- The input must be between -1 and 1; outside that range it throws
- The result is in radians, ranging from 0 to π
- It is the inverse of $cos
🏷️ Related Tags
💡 Related Cases
More hands-on cases coming soon.
📚 Related Tutorials
❓ FAQ
QWhat is the result range of $acos?
AFrom 0 to π radians, which is 0 to 180 degrees.
QHow do $acos and $asin differ?
AThey share the input range (-1 to 1), but $acos results span 0 to π while $asin results span -90 to 90 degrees.
QWhat is $acos(1)?
AIt is 0, since the cosine of zero radians is 1.