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

12,696

Solution 1

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() {});

Solution 2

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

mongoose api

Share:
12,696

Related videos on Youtube

Dan Steele
Author by

Dan Steele

Updated on September 20, 2022

Comments

  • Dan Steele
    Dan Steele over 1 year

    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?

  • chovy
    chovy over 3 years
    how to use with promises?