Exceeded memory limit for $group

  mongodb, question

Exceeded memory limit for $group, but didn’t allow external sort. Pass allowDiskUse:true to opt in

query_data_total = coll.aggregate([
 {"$match": {"order_date": {"$gte": start_date, "$lte": end_date},
 {"$group": {"_id": "$order_date",
 "gmv": {"$sum": "$price"}, "ticket_num": {"$sum": 1}, "order_num": {"$addToSet": "$order_id"}}
 We use aggregate to aggregate the query, but there is no problem when querying the data for a few days. When the number of days is too large, we use pymongo to report the error.

$group has a memory limit. your data volume exceeded the limit and you did not specify that you are allowed to use additional disks for operations, so you reported an error.
The $group stage has a limit of 100 megabytes of RAM. By default, if the stage exceeds this limit, $group will produce an error. However, to allow for the handling of large datasets, set the allowDiskUse option to true to enable $group operations to write to temporary files.See db.collection.aggregate() method and the aggregate command for details.