Facet exceeding it's limit

Hi all,
I’ve run into an issue and I’m not sure how to best approach finding a solution.
I’m using MongoDB 5.3.1 Community and MongoDB Compass. I have a database that contains a collection of “Dealers”. Each dealer record contains information about a customer and a list of vehicles they have in stock. In turn, each Vehicle record contains information about the vehicle and 2 arrays, one of associated images and the other about the vehicles specifications.

We are not talking large amounts of data. The Dealer collection only contains 57 records, and the largest number of vehicles is 113 records.

I’ve created an aggregate that:

  1. first matches the required dealer id.
  2. unwinds the Vehicles records.
  3. and this is where it bombs. I’m trying to create a facet stage, but I’m getting this error:

PlanExecutor error during aggregation :: caused by :: document constructed by $facet is 104910678 bytes, which exceeds the limit of 104857600 bytes

The aggregate is literally this:

[
  {
    '$match': {
      'Id': 321 // Note this is not a Mongo _id but a distinct ID from a legacy system.
    }
  }, {
    '$unwind': {
      'path': '$Vehicles'
    }
  }, {
    '$facet': {
      'test': []
    }
  }
] 

I don’t do anything in the facet stage and it still bombs.

I’ve not played with the allowDiskUse, because I wasn’t sure it should be throwing this sort of error, with this amount of data. I could be wrong.

If I turn off the facet stage and export the aggregate result, the output Json file is only 3.12MB.

Any advice would be greatly received. Tips on how to trouble shoot, possible reasons, what to do next.

Thanks in advance.

Hi @Andy_Bryan ,

Try to add the allowDiskUse: true to your query:

Thanks
Pavel

Just to double check. Should it be throwing this sort of error at the level of data I’m using?

Running an empty facet might blow the stage

Unfortunately, that didn’t resolve the issue. After doing a bit of digging, this actually sorted my problem.

db.adminCommand({setParameter: 1, internalQueryFacetMaxOutputDocSizeBytes: 335544320})
1 Like

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.