db.command.aggregate.ln
1. Operator Description
Function: Calculates the natural logarithm of a given number.
Declaration: db.command.aggregate.ln(number)
Notes:
ln
is equivalent tolog([<number>, Math.E])
, whereMath.E
is the method in JavaScript to get the value ofe
.
2. Operator Parameters
Field | Type | Required | Description |
---|---|---|---|
- | Expression | Required | <number> can be any expression that evaluates to a non-negative number. |
3. Sample Code
Suppose the collection staff
contains the following records:
{ _id: 1, x: 1 }
{ _id: 2, x: 2 }
{ _id: 3, x: 3 }
Calculate the value of ln(x)
:
// Sample code in the Cloud Function environment
const tcb = require('@cloudbase/node-sdk')
const app = tcb.init({
env: 'xxx'
})
const db = app.database()
const $ = db.command.aggregate
exports.main = async (event, context) => {
const res = await db
.collection('ratings')
.aggregate()
.project({
ln: $.ln('$x')
})
.end()
console.log(res.data)
}