Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there any way to supply the allowDiskUse option to an mongoose.js aggregation?

I'm running an aggregation on a collection of around 300k+ records which requires several unwinds and regroups. I'm hitting the following error;

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

I can't seem to work out how to pass this option through using the mongoose.js API?

like image 576
Dan Steele Avatar asked May 27 '14 16:05

Dan Steele


3 Answers

We don't have a helper for this right now, but an allowDiskUse() helper function will be included in Mongoose 3.8.12, which I'll ship today: https://github.com/LearnBoost/mongoose/issues/2114

If you want an immediate solution or don't want to upgrade to 3.8.12 (although upgrading is recommended), you can do something like:

var aggregation = MyModel.aggregate(...); 
aggregation.options = { allowDiskUse: true }; 
aggregation.exec(function() {});
like image 138
Valeri Karpov Avatar answered Oct 06 '22 17:10

Valeri Karpov


Model.aggregate(..).allowDiskUse(true).exec(callback)

mongoose api

like image 23
glowry Avatar answered Oct 06 '22 18:10

glowry


const agg = Model.aggregate(..).option({ allowDiskUse: true });

worked for me as per the Mongoose V6.0.4 documentation here

like image 1
dc7 Avatar answered Oct 06 '22 17:10

dc7