db.command.aggregate.log10
1. Operator Description
Function: Computes the logarithm of a given number with base 10.
Syntax: db.command.aggregate.log10(number)
Notes:
log10
is equivalent to thelog
method with its second parameter fixed at 10.
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 log10(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({
log10: $.log10('$x')
})
.end()
console.log(res.data)
}