$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).

CategoryMath
MongoDB Version1.0+
Example Languagemongosh (Shell)

📝 Syntax

{ $acos: <numeric-expression> }

⚙️ Parameters

numeric valueA 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

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.
Web-Tutorial.com

Web-Tutorial Tech Team

A team of developers maintaining programming tutorials. Each tutorial is written and reviewed by developers with expertise in that field. We work to keep our content accurate and reliable — if you spot an issue, please let us know.

100%

🙏 帮我们做得更好

我们是刚上线的编程教程站,几个人的小团队,精力有限。页面虽经检查,难免还有疏漏——链接失效、排版错乱、内容有误、语言生硬……

如果您发现了,麻烦告诉我们,我们会在收到反馈后第一时间进行修复,再次感谢您的光临 🙏