$acos
New from version 8.0.1.
The $acos operator in Amazon DocumentDB returns the arccosine (inverse cosine) of a value. The input value must be between -1 and 1.
Parameters
-
expression: An expression that resolves to a number between -1 and 1.
The result is in radians. To obtain degrees, apply $radiansToDegrees to the output.
The return type is double by default. If the input is a 128-bit decimal, the output is also a 128-bit decimal.
Example (MongoDB Shell)
The following example shows how to use the $acos operator to calculate the arccosine of numeric values.
Create sample documents
db.values.insertMany([ { "_id": 1, "value": 1 }, { "_id": 2, "value": 0 }, { "_id": 3, "value": -1 } ]);
Query example
db.values.aggregate([ { $project: { "angle": { $acos: "$value" } }} ]);
Output
[
{ "_id": 1, "angle": 0 },
{ "_id": 2, "angle": 1.5707963267948966 },
{ "_id": 3, "angle": 3.141592653589793 }
]
Code examples
To view a code example for using the $acos operator, choose the tab for the language that you want to use: