将createView与allowDiskUse一起使用 [英] Use createView with allowDiskUse

查看:105
本文介绍了将createView与allowDiskUse一起使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在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一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆