0

我正在使用spring批处理框架来处理mongo db中的大量数据并再次存储在mongo db中

代码如下:

Aggregation agg = newAggregation(           
            project("field1")                   
                //projection on few fields                  
            group("field1")             
                //group opeartion               
            project(                
                // again project on grouped result              
            )
).withOptions(newAggregationOptions().allowDiskUse(true).build());

AggregationResults<BeanName> agreatiR = dbTemplate.aggregate(agg,collectionName,BeanName.class);

对于较少的数据(我已经在 100k 上进行了测试),聚合框架工作正常,但对于 2M,它给出了超过 16 MB 限制的例外情况。

我不想使用 $out 操作,因为首先它不是必需的,而且似乎没有任何 API 可以在 spring data mongo 中使用 $out

我也读过返回游标,这将允许超出大小限制,但似乎没有任何支持它的 spring 数据 mongo API。

Mongo DB 版本:2.6

Mongo 驱动程序版本:3.2.0

4

1 回答 1

0

我知道您正在尝试立即提交 2M。这很糟糕,因为将所有 bean 加载到内存中。

您应该使用commit-interval以减少这项巨大的工作。你这样做了吗?

<tasklet transaction-manager="transactionManager">
        <chunk reader="itemReader" writer="itemWriter" commit-interval="500"/>
    </tasklet>

请参阅官方文档中的配置步骤

于 2016-05-13T14:35:52.720 回答