$sin - Amazon DocumentDB
Services or capabilities described in AWS documentation might vary by Region. To see the differences applicable to the AWS European Sovereign Cloud Region, see the AWS European Sovereign Cloud User Guide.

$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 $sin 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:

Node.js
const { MongoClient } = require('mongodb'); async function main() { const client = await MongoClient.connect('mongodb://<username>:<password>@<cluster-endpoint>:27017/?tls=true&tlsCAFile=global-bundle.pem&replicaSet=rs0&readPreference=secondaryPreferred&retryWrites=false'); const db = client.db('test'); const collection = db.collection('angles'); const result = await collection.aggregate([ { $project: { "sine": { $sin: "$angle" } }} ]).toArray(); console.log(result); await client.close(); } main();
Python
from pymongo import MongoClient def main(): client = MongoClient('mongodb://<username>:<password>@<cluster-endpoint>:27017/?tls=true&tlsCAFile=global-bundle.pem&replicaSet=rs0&readPreference=secondaryPreferred&retryWrites=false') db = client['test'] collection = db['angles'] result = list(collection.aggregate([ { '$project': { 'sine': { '$sin': '$angle' } }} ])) print(result) client.close() if __name__ == "__main__": main()