MongoDB $nin query exceeds BSON document size limitation

273 views Asked by At

I am performing a simple query using Pymongo against a list of filenames:

db.FileAssets.find({'filename': {'$nin': filenames}}})

However, the query is throwing the DocumentTooLarge error. The length of the filenames list is 152098 and the Python object size is 1320856. Pymongo states the query is 20791219 bytes so I'm guessing that whatever MongoDB does internally to perform the $nin is overloading the doc size. What is an alternative way to perform this query?

1

There are 1 answers

0
wowkin2 On

Most likely it is about Response object. It can take too much memory in MongoDB.
Sometimes, adding new indexes can resolve this issues.