$sin
New from version 8.0.1.
The $sin operator in Amazon DocumentDB returns the sine of a value that is measured in radians. Use it in the aggregation pipeline to perform trigonometric calculations on numeric fields.
Parameters
-
expression: An expression that resolves to a number in radians.
Example (MongoDB Shell)
The following example shows how to use the $sin operator to calculate the sine of angle values in radians.
Create sample documents
db.angles.insertMany([ { "_id": 1, "angle": 0 }, { "_id": 2, "angle": 0.5235987755982988 }, { "_id": 3, "angle": 1.5707963267948966 } ]);
Query example
db.angles.aggregate([ { $project: { "sine": { $sin: "$angle" } }} ]);
Output
[
{ "_id": 1, "sine": 0 },
{ "_id": 2, "sine": 0.49999999999999994 },
{ "_id": 3, "sine": 1 }
]
Code examples
To view a code example for using the $sin operator, choose the tab for the language that you want to use: