MongoDB allowDiskUse不工作..

Eya*_*der 12 mapreduce mongodb aggregation-framework

专家们.

我是MongoDB的新手,但我知道自己遇到了麻烦......例如:

db.test.aggregate(
[
    {$group: {_id: {email: "$email", gender: "$gender"}, cnt: {$sum: 1}}}, 
    {$group: {_id: "$_id.email", cnt: {$sum: 1}}}, 
    {$match: {cnt: 2}}
], 
    {allowDiskUse : true}
)
Run Code Online (Sandbox Code Playgroud)

无论我尝试什么变化,我都会遇到同样的错误("Pass allowDiskUse:true to opt in"):

错误("打印堆栈跟踪")@:0()@src/mongo/shell/utils.js:37([对象数组],[对象对象])@src/mongo/shell/collection.js:866 @(壳):7

未捕获的异常:聚合失败:{"errmsg":"异常:来自mongo1.mscnet.com:27017的响应中收到错误:{$ err:\"超出$ group的内存限制,但不允许外部排序.传递allowDiskUse:true以选择加入. \",代码:16945}","code":16945,"ok":0}

仅供参考:我使用的是Mongo 2.6

Din*_*aws 18

请在运行命令中使用聚合查询,它将允许使用allowDiskUse标记.

db.runCommand(
   { aggregate: "test",
     pipeline: [
                {$group: {_id: {email: "$email", gender: "$gender"}, cnt: {$sum: 1}}}, 
                {$group: {_id: "$_id.email", cnt: {$sum: 1}}}, 
                {$match: {cnt: 2}}
               ],
     allowDiskUse: true
   }
)
Run Code Online (Sandbox Code Playgroud)


小智 8

Try writing like this,

db.stocks.aggregate([
                     { $project : { cusip: 1, date: 1, price: 1, _id: 0 } },
                     { $sort : { cusip : 1, date: 1 } }
                    ],
                     {
                       allowDiskUse: true
                     }
                    ); 
Run Code Online (Sandbox Code Playgroud)

And One more thing,
Your error about maximum document size is inherent to Mongo. Mongo can never return a document (or array thereof) larger than 16 megabytes. I can't tell you why because you didn't mention anything about data size, but it probably means that the document you're building as an end result is too large. Try decreasing the $limit parameter, maybe? Start by setting it to 1, run a test, then increase it and look at how big the result gets when you do that


小智 8

如果您正在使用m10 或更高版本的 MongoDB Atlas,以下是修复{allowDiskUse: true}; 如果您通过 mongoose 从应用程序访问数据,则它应该是语法即函数。例如:

MongoDb 查询:

db.collection.user.aggregate([], {allowDiskUse: true})
Run Code Online (Sandbox Code Playgroud)

猫鼬:

User.aggregate([]).allowDiskUse(true);
Run Code Online (Sandbox Code Playgroud)

这将解决应用程序中的错误:)