allowDiskUse:true not working

I am trying to execute an execution query which has these stages:

  1. $addFields
  2. $group
  3. $project
  4. $merge
    The collection on which I’m running the aggrregation query has 449.4k records and the collection size is around 200mb.

When I run the aggregation query I get an error message saying:
PlanExecutor error during aggregation :: caused by :: Exceeded memory limit for $group, but didn't allow external sort. Pass allowDiskUse:true to opt in

I’m trying to use {allowDiskUse: true} like this

db.collectionName.aggregate(aggregateQuery,{
    allowDiskUse: true,
})

but it didn’t work. and is returning the same error message.

How I can fix it?
note: I’m using Atlas Severless and dedicated clusters of M40 (General) tier

Hi @Prasanjit_Dutta,

Welcome to the MongoDB Community forums

As per the documentation, the limit for each aggregation pipeline stage is 100 MB. So, using allowDiskUse:true allows writing temporary files on disk when a pipeline stage exceeds the 100-megabyte limit. Starting in MongoDB 6.0, operations that require greater than 100 MB of memory automatically write data to temporary files by default.

So, here, I assume you are using a cluster < v6.0. Therefore, please ensure you are passing it syntactically correctly.

db.collectionName.aggregate
(
  [ { <aggregation pipeline stages> } ],
  { allowDiskUse: true }
);

In case your problem persists, please share the sample document and the aggregation pipeline so the community can better assist you.

Best regards,
Kushagra

3 posts were split to a new topic: allowDiskUse:true is not working - M0

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