【问题标题】:MongoDB aggregation pipeline $limit cast exception from string to intMongoDB 聚合管道 $limit 将异常从字符串转换为 int
【发布时间】:2021-03-12 02:47:34
【问题描述】:

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

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

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

更多详情:

【问题讨论】:

    标签: mongodb mongodb-query aggregation-framework bson


    【解决方案1】:

    来自官方文档here

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

    { $limit: <positive integer> }

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

    【讨论】:

    • 感谢您的宝贵时间,同意文档说它只支持正整数。价值将来自服务动态。因此,按照here 的建议使用类型转换(从字符串到 INT)。这里的问题是类型转换不起作用
    • 我认为在 $limit 之后,需要一个整数,而不是
    • 是在 Mongo Pipe Linequery $skip 和 $limit 中不接受任何表达式并且类型转换它只接受整数。通过在服务器端使用管道查询的字符串替换来修复问题。
    猜你喜欢
    • 2019-11-29
    • 2019-02-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-03-20
    相关资源
    最近更新 更多