在mongo聚合框架中可以使用选项{allowDiskUse:true}.当某些繁重的操作(例如排序)无法在内存中执行时,这真的很有用.
In the mongo aggregation framework is possible to use the option {allowDiskUse:true}. This is really useful when some heavy operations such as sorting, which cannot be performed in memory.
我正在尝试对createView做同样的操作(在Mongo 3.4中可用),但是我找不到可以引入allowDiskUse的地方.
I'm trying to do the same with createView (available in Mongo 3.4), but I cannot find the place where allowDiskUse can be introduced.
在常规聚合框架中:
db.mydb.aggregate([....,{$sort:{"a":-1}}],{allowDiskUse:true})可以,但是:
db.createView("newview","mydb",[....,{$sort:{"a":-1}}],{allowDiskUse:true})产生错误
The field 'allowDiskUse' is not a valid collection option.当然,我可以删除{allowDiskUse:true}.然后创建了视图,但是当我尝试时:
Of course, I can just remove {allowDiskUse:true}. Then the view is created, but when I try:
> db.newview.find() Error: error: { "ok" : 0, "errmsg" : "Sort exceeded memory limit of 104857600 bytes, but did not opt in to external sorting. Aborting operation. Pass allowDiskUse:true to opt in.", "code" : 16819, "codeName" : "Location16819" }如何创建包含大型操作的视图?
How to create a view that include large operations?
推荐答案以防万一有人发现相同的问题,jira的Kyle Suarez提出了以下解决方法:
Just in case someone finds the same problem, Kyle Suarez at jira proposed the following workaround:
db.newview.aggregate([], { allowDiskUse: true });也就是说,在视图上使用聚合即可解决问题.
that is, using an aggregation on the view solves the problem.
更多推荐
将createView与allowDiskUse一起使用
发布评论