【问题标题】:Is there any way to supply the allowDiskUse option to an mongoose.js aggregation?有没有办法为 mongoose.js 聚合提供 allowDiskUse 选项?
【发布时间】:2014-07-16 15:23:21
【问题描述】:

我正在对大约 300k+ 条记录的集合进行聚合,这需要多次展开和重新组合。我遇到了以下错误;

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

我似乎不知道如何通过使用 mongoose.js API 传递此选项?

【问题讨论】:

    标签: node.js mongodb mongoose aggregation-framework


    【解决方案1】:

    我们目前还没有这方面的助手,但 allowDiskUse() 助手函数将包含在 Mongoose 3.8.12 中,我将在今天发布:https://github.com/LearnBoost/mongoose/issues/2114

    如果您想要立即解决或不想升级到 3.8.12(尽管建议升级),您可以执行以下操作:

    var aggregation = MyModel.aggregate(...); 
    aggregation.options = { allowDiskUse: true }; 
    aggregation.exec(function() {});
    

    【讨论】:

    • 如何与promises一起使用?
    【解决方案2】:
    Model.aggregate(..).allowDiskUse(true).exec(callback)
    

    mongoose api

    【讨论】:

      【解决方案3】:
      const agg = Model.aggregate(..).option({ allowDiskUse: true });
      

      根据 Mongoose V6.0.4 文档here为我工作

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-11-25
        • 1970-01-01
        • 2019-12-29
        • 2018-05-16
        • 2021-10-11
        • 2020-02-24
        相关资源
        最近更新 更多