Error: BSONObj size: 66093317 (0x3F08105) is invalid


in function facetedSearch() insinde moviesDAO.js file there is facet stage facetStage = { $facet: … }.

I tried to implement this in Compass. First two (sub)stages, for runtime and rating,are passing, but with $addFields stage it doesn’t and it throws an error:

BSONObj size: 66093476 (0x3F081A4) is invalid. Size must be between 0 and 16793600(16MB) First element: runtime: [ { _id: 0, count: 2310 }, { _id: 60, count: 11440 }, { _id: 90, count: 24244 }, { _id: 120, count: 4768 }, { _id: “other”, count: 3231 } ]

I provided screenshots of both cases.

Also. when I use $addFields as a stage alone(without $facet) it passes. (screenshot for that too)!

So my question is why it fails inside $facet stage? I can see it is something with memory, and I know about allowDiskUse, but not sure if I can apply that here?
And also what is purpose of $addFields: { title: “$title” }, we are adding new field that is same as one we already have projected?


Hi @AleksandarVeselinovic,

I tried the same $facet stage in Compass and got the same error message. The difference why it is working from js code and not in Compass is some stages might be missing in your aggregation pipeline like $match stage which will automatically filter and will result in less documents so the memory issue won’t be there.

For example, it worked when I used $match stage before running the $facet stage:


Hi Kanika, thanks for answer.

Yes this work, but what if after matching(filtering) we got a large data set ( > 16MB ). Is there way to resolve this problem. Can we include somehow include allowDiskUse ?