【问题标题】:Does MongoDB's $in clause has any max limit in number of argumentsMongoDB 的 $in 子句是否有参数数量的最大限制
【发布时间】:2016-06-06 16:15:53
【问题描述】:

当使用 MongoDB 的 $in 子句和 Aggregate 时,参数数量是否有最大限制?

例如

Model.aggregate(
        [
            { $match : 
                { '_Id' : 
                            {
                                $in : ids
                            }
                }
            } ,
            { $group : 
                {   _id : '$roomId' ,
                    maxdate: { $max: "$date"},
                }
            },
            {$sort: { maxdate: -1} },
            {$skip: skip},
            {$limit: limitNum }
        ]

在 ids 数组中,我可以传递多少个 id?

目前在 50,000 之前我没有遇到 ids 长度的任何问题......但为了安全起见,我想知道最大限制。

我尝试在 Mongo doc 上进行搜索,但没有找到任何内容。

提前致谢。

【问题讨论】:

    标签: mongodb mongoose aggregation-framework


    【解决方案1】:

    $in 子句本身的参数数量没有限制,但是,总查询大小限制为 16MB,因为查询只是一个 BSON 文档。根据 ids 使用的类型(请参阅 BSON specification),当您的 id 长度大约为几百万时,您可能会开始遇到问题。

    【讨论】:

    • 如果 ids 长度为数百万,我们会遇到什么问题......因为你的评论现在已经 5 年了......在 mongodb 中是固定的吗?
    猜你喜欢
    • 2017-06-07
    • 2019-03-31
    • 2010-11-03
    • 1970-01-01
    • 2012-02-24
    • 2014-08-30
    • 2012-02-07
    • 1970-01-01
    相关资源
    最近更新 更多