What is the maximum number of parameters passed to $in query in MongoDB?

前端 未结 4 1071
梦毁少年i
梦毁少年i 2020-12-05 17:05

What is the maximum number of parameters passed to $in query in MongoDB?

4条回答
  •  无人及你
    2020-12-05 17:29

    I think the limitation is just determined by the size of a BSONDocument. When you define a query, you can keep adding values into an $in clause up until you exceed the maximum document size. So how many values you can have in the clause depends on how big each value is (the smaller the size of each value, the more you can include in the $in clause).

    In terms of performance, from what I've found, there is a "sweet spot" for the number of values in an $in clause. See my answer in this related question: Is it OK to query a MongoDB multiple times per request?

    i.e. balancing number of values in $in clause vs number of queries sent. I'm mid way through a blog post on that to try and dive into more detail.

提交回复
热议问题