$tan
New from version 8.0.1.
The $tan operator in Amazon DocumentDB returns the tangent of a value that is measured in radians.
The input expression must resolve to a numeric value. If your value is in degrees, apply $degreesToRadians before passing it to $tan.
The return type is double by default. If the input is a 128-bit decimal, the output is also a 128-bit decimal.
Parameters
-
expression: An expression that resolves to a number in radians.
Behavior
null, NaN, and +/- Infinity
| Example | Results |
|---|---|
{ $tan: NaN } |
NaN |
{ $tan: null } |
null |
{ $tan: Infinity } or { $tan: -Infinity } |
Throws an error. |
When the input is null or the referenced field is missing, $tan returns null. An input of NaN produces NaN. Positive or negative infinity causes an error because tangent is undefined at those values.
Example (MongoDB Shell)
The following example shows how to use the $tan operator to calculate the tangent of an angle in radians.
Create sample documents
db.angles.insertMany([ { "_id": 1, "angle": 0 }, { "_id": 2, "angle": 0.7853981633974483 }, { "_id": 3, "angle": -0.7853981633974483 } ]);
Query example
db.angles.aggregate([ { $project: { "tangent": { $tan: "$angle" } }} ]);
Output
[
{ "_id": 1, "tangent": 0 },
{ "_id": 2, "tangent": 0.9999999999999999 },
{ "_id": 3, "tangent": -0.9999999999999999 }
]
Code examples
To view a code example for using the $tan operator, choose the tab for the language that you want to use: