Supported platforms: Mini Program 2.7.4, Cloud Function 0.8.1, Web
Aggregation operator. Truncates a number to an integer.
Parameters
value: Expression<number>
number
Return Value
Object
API Description
The syntax is as follows:
db.command.aggregate.trunc(<number>)
The argument can be any expression that resolves to a number.
Sample Code
Assume the collection scores has the following records:
{ "_id": 1, "value": 1.21 }
{ "_id": 2, "value": 3.83 }
{ "_id": 3, "value": -4.94 }
const $ = db.command.aggregate
db.collection('scores').aggregate()
.project({
int: $.trunc('$value')
})
.end()
The result is as follows:
{ "_id": 1, "value": 1 }
{ "_id": 2, "value": 3 }
{ "_id": 3, "value": -4 }