Para agentes de IA: um índice de documentação está disponível em https://www.mongodb.com/pt-br/docs/llms.txt — as versões de markdown de todas as páginas estão disponíveis anexando .md a qualquer caminho de URL.
Menu Docs

$tan (operador de expressão )

$tan

Retorna a tangente de um valor que é medido em radianos.

$tan tem a seguinte sintaxe:

{ $tan: <expression> }

$tan takes any valid expression that resolves to a number. If the expression returns a value in degrees, use the $degreesToRadians operator to convert the result to radians.

By default $tan returns values as a double. $tan can also return values as a 128-bit decimal as long as the <expression> resolves to a 128-bit decimal value.

Para mais informações sobre expressões, consulte Expressões.

If the argument resolves to a value of null or refers to a field that is missing, $tan returns null. If the argument resolves to NaN, $tan returns NaN. If the argument resolves to negative or positive infinity, $tan throws an error.

Exemplo
Resultados

{ $tan: NaN }

NaN

{ $tan: null }

null

{ $tan : Infinity}

ou

{ $tan : -Infinity }

Lança uma mensagem de erro semelhante à seguinte saída formatada:

"errmsg" :
"Failed to optimize pipeline :: caused by :: cannot
apply $tan to -inf, value must in (-inf,inf)"

A collection trigonometry contém um documento que armazena um lado e um ângulo em um triângulo retângulo:

{
"_id" : ObjectId("5c50782193f833234ba90d85"),
"angle_a" : Decimal128("53.13010235415597870314438744090659"),
"side_a" : Decimal128("3")
}

The following aggregation operation uses the $tan expression to calculate the side opposite to angle_a and add it to the input document using the $addFields pipeline stage.

db.trigonometry.aggregate([
{
$addFields : {
"side_b" : {
$multiply : [
{ $tan : {$degreesToRadians : "$angle_a"} },
"$side_a"
]
}
}
}
])

A expressão $degreesToRadians converte o valor do grau de angle_a no valor equivalente em radianos.

O comando retorna a seguinte saída:

{
"_id" : ObjectId("5c50782193f833234ba90d85"),
"angle_a" : Decimal128("53.13010235415597870314438744090659"),
"side_a" : Decimal128("3")
"side_b" : Decimal128("4.000000000000000000000000000000000")
}

Since angle_a and side_a are stored as 128-bit decimals, the output of $tan is a 128-bit decimal.

Avalie esta página