MongoDB 允许磁盘使用不起作用..

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/27491245/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 20:14:25  来源:igfitidea点击:

MongoDB allowDiskUse not working..

mongodbmapreduceaggregation-framework

提问by Eyal Zinder

Experts.

专家。

I'm new to MongoDB, but know enough to get my self in trouble.. case in point:

我是 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}
)

and no matter what variations I try, I keep getting the same error ("Pass allowDiskUse:true to opt in"):

无论我尝试什么变化,我都会收到相同的错误(“通过 allowDiskUse:true 选择加入”):

Error("Printing Stack Trace")@:0 ()@src/mongo/shell/utils.js:37 ([object Array],[object Object])@src/mongo/shell/collection.js:866 @(shell):7

uncaught exception: aggregate failed: { "errmsg" : "exception: Received error in response from mongo1.mscnet.com:27017: { $err: \"Exceeded memory limit for $group, but didn't allow external sort. Pass allowDiskUse:true to opt in.\", code: 16945 }", "code" : 16945, "ok" : 0 }

Error("打印堆栈跟踪")@:0 ()@src/mongo/shell/utils.js:37 ([object Array],[object Object])@src/mongo/shell/collection.js:866 @(外壳):7

未捕获的异常:聚合失败:{“errmsg”:“异常:从 mongo1.mscnet.com 收到错误响应:27017:{ $err:\”超出了 $group 的内存限制,但不允许外部排序。通过 allowDiskUse:true 选择加入。\", code: 16945 }", "code" : 16945, "ok" : 0 }

FYI: I'm using Mongo 2.6

仅供参考:我正在使用 Mongo 2.6

回答by Dineshaws

Please use aggregate query in run command,it will allow to use allowDiskUse tag.

请在运行命令中使用聚合查询,它将允许使用 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
   }
)

回答by MAULIK MODI

Try writing like this,

试试这样写

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

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

还有一件事,
您关于最大文档大小的错误是 Mongo 固有的。Mongo 永远不能返回大于 16 兆字节的文档(或其数组)。我无法告诉您原因,因为您没有提到任何有关数据大小的内容,但这可能意味着您作为最终结果构建的文档太大。尝试减少 $limit 参数,也许?首先将它设置为 1,运行一个测试,然后增加它并看看当你这样做时结果有多大

回答by pushpak

If you are working with m10 or laterversion of MongoDB Atlas, below is the fix for {allowDiskUse: true};If you are accessing data from application via mongoose then, it should be syntax as function. For example:

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

MongoDb Query:

MongoDb 查询:

db.collection.user.aggregate([], {allowDiskUse: true})

With Mongoose:

猫鼬:

User.aggregate([]).allowDiskUse(true);

This will resolve error from application :)

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