MongoDB 聚合管道 $limit 从字符串到 int 的转换异常

MongoDB aggregation pipeline $limit cast exception from string to int

尝试在聚合中从 string 转换为 int 会引发以下错误:$limit should be a number not object or string。这是我的查询:

{ $limit: { "$convert": { "input": "10", "to": "int" } } }

{ $limit: { $toInt: "5" } }

更多详情:

来自官方文档here,

$limit阶段的原型形式如下:

{ $limit: <positive integer> }

我认为你只能使用正整数。您需要将其设为整数而不是字符串。