$sin (Sine)
Last updated: 2026-10-09
$sin (Sine)
$sin returns the sine of a value expressed in radians. It is used for periodic signal processing, coordinate transforms, and trigonometry, such as converting degrees to radians before taking the sine. A null or missing argument yields null, NaN input returns NaN, and ±Infinity throws an error. Convert degrees to radians with $degreesToRadians (and back with $radiansToDegrees) instead of hand-multiplying by pi.
| Category | Math |
|---|---|
| MongoDB Version | 1.0+ |
| Example Language | mongosh (Shell) |
📝 Syntax
{ $sin: <numeric-expression> }
⚙️ Parameters
| radians | A numeric expression in radians. |
|---|
Returns:The sine of the input radians; null when null or missing, error for ±Infinity
▶ Example
Run the commands below in your local mongosh (requires a running mongod):
// $sin: sine after converting degrees to radians
db.trig.aggregate([
{ $project: {
y: { $sin: { $degreesToRadians: '$deg' } }
} }
])
Output:
{ '_id': 1, 'y': 1 }
{ '_id': 2, 'y': 0.5 }
📌 Notes
- The input is in radians; convert angles first
- ±Infinity input throws an error
- Part of the $cos and $tan family; $asin gives the inverse
🏷️ Related Tags
💡 Related Cases
More hands-on cases coming soon.
📚 Related Tutorials
❓ FAQ
QDoes $sin take degrees or radians?
ARadians; convert angle input with $degreesToRadians first.
QWhat does $sin return for Infinity?
AIt throws; the sine of infinity is undefined.
QHow do I compute $sin(30 degrees)?
AWrite $sin: { $degreesToRadians: 30 } and the result is 0.5.