MongoDB 的 $in 子句是否有参数数量的最大限制 [英] Does MongoDB's $in clause has any max limit in number of arguments

查看:18
本文介绍了MongoDB 的 $in 子句是否有参数数量的最大限制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

When using MongoDB's $in clause with Aggregate , Does That has any max limit in number of arguments ?

例如

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

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

In ids array , how many ids i can pass ?

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

Currently i am not facing any issue with ids length till 50,000 ... but for safe side wanted to know the max limit.

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

I have tried to search on Mongo doc , but didnt find anything.

提前致谢.

推荐答案

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

There is no limit to the number of arguments in the $in clause itself, however, the total query size is limited to 16MB as a query is just a BSON document. Depending on the type used for ids (see the BSON specification), you may start running into problems when your ids length is in the order of a few millions.

这篇关于MongoDB 的 $in 子句是否有参数数量的最大限制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆