mongodb - Exceeded memory limit for $group

 青锋寒万岁 发布于 2022-10-26 20:55

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"}}
     }
])

使用aggregate聚合查询  但查询几天的数据的时候没有问题  当天数多了之后就报错 用的是pymongo
1 个回答
  • $group有内存限制你的数据量超过了限制而且没有指定允许使用额外的磁盘进行操作于是就报错了
    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.

    2022-10-27 01:30 回答
撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有