在POST请求调用MongoDB聚合函数时如何设置allowDiskUse=true
Fixing MongoDB Aggregation Memory Limit Error in Postman
To resolve the Exceeded memory limit for $group error, you need to add the allowDiskUse: true parameter to your POST request body. This lets MongoDB use disk storage for intermediate aggregation results when memory limits are hit.
Corrected Request Body Structure
Adjust your JSON payload to include allowDiskUse as a top-level property, and ensure your aggregation pipeline is properly nested under the pipeline key. The aggregate key should specify your target collection name:
{ "aggregate": "your_collection_name", "pipeline": [ { "$group": { "_id": { "mac_address": "$mac", "address": "$ip" }, "hostnames": { "$addToSet": "$hostname" }, "interfaces": { "$addToSet": "$interfaceName" } } }, { "$project": { "_id": 0, "mac_address": "$_id.mac_address", "address": "$_id.address", "hostnames": "$hostnames", "interfaces": "$interfaces" } } ], "allowDiskUse": true }
For MongoDB Atlas Data API Users
If you're using the Atlas Data API, the request structure will include database and collection fields instead of the top-level aggregate key. Add allowDiskUse at the top level here as well:
{ "database": "your_database_name", "collection": "your_collection_name", "pipeline": [ // Your existing pipeline stages here ], "allowDiskUse": true }
Steps in Postman
- Open your POST request in Postman.
- Navigate to the Body tab and select raw > JSON.
- Replace your current payload with the corrected structure above, filling in your actual collection/database names.
- Send the request again—MongoDB will now use disk storage to handle the large aggregation.
内容的提问来源于stack exchange,提问作者learnerNT
相关产品推荐
相关产品推荐

