Does MongoDB's $in clause has any max limit in number of arguments

雨燕双飞 提交于 2021-02-19 02:57:33

问题


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

for example

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

In ids array , how many ids i can pass ?

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

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

Thanks in advance.


回答1:


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.



来源:https://stackoverflow.com/questions/35601048/does-mongodbs-in-clause-has-any-max-limit-in-number-of-arguments

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!