结果中的value应该为int
发布于 4 年前 作者 liaoyan 6071 次浏览 来自 官方Issues

https://developers.weixin.qq.com/miniprogram/dev/wxcloud/reference-sdk-api/database/command/aggregate/AggregateCommand.trunc.html

示例代码

假设集合 scores 有如下记录:

{ "_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()

返回结果如下:

{ "_id": 1, "value": 1 }
{ "_id": 2, "value": 3 }
{ "_id": 3, "value": -4 }
结果中的value应该为int,正确写法:
{ "_id": 1, "int": 1 }
{ "_id": 2, "int": 3 }
{ "_id": 3, "int": -4 }

回到顶部