mongodb – Maximum number of values ​​in $ in

Question:

The question arose: what is the maximum number of values ​​that can be put into $in in mongo?

{ $in: [<value1>, <value2>, ... <valueN> ] }

Answer:

In English-speaking SO, enthusiasts have done a research and found out that the number of objects in $ in is not formally limited, but since an object is sent as an argument to .find() , it is also subject to the MongoDB object size limit of 16 MB.

Object.bsonsize({ 'field' : { $in : [ value1, value2, ..., valueN] } })

This code will give you the size of your request. Probably, the larger the size of any field and valueX , the less they will fit into the request.

Conclusion:

If the goal is to send the maximum number of options in $in , then one friend claims that the maximum number of items in $in approximately 1.5 million

If the goal is a practical application, then the limitation can be safely ignored)

Scroll to Top