有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

spring Mongo使用java驱动程序对大数据进行聚合查询?

我正在使用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,它给出了16MB限制的例外

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

我还读到过一些返回游标的文章,这些游标将允许超出大小限制,但似乎没有任何spring data mongo API支持这一点

Mongo DB版本:2.6

Mongo驱动程序版本:3.2.0


共 (1) 个答案

  1. # 1 楼答案

    我知道你在试图马上做出200万美元的承诺。这很糟糕,因为在内存中加载所有bean

    你应该使用commit-interval来减少这项庞大的工作。你做到了吗

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

    see configuring a step in official doc