我面临以下问题
com.mongodb.CommandFailureException: { "serverUsed" : "127.0.0.1:15847" , "errmsg" : "exception: aggregation result exceeds maximum document size (16MB)" , "code" : 16389 , "ok" : 0.0}
> {“ $out”:“ temp_colls”);
> useCursor =真
第一个正在为我工作,但是它花费了大约3-4分钟的太多时间.
所以寻找下面我尝试过的第二种选择
原始代码是
dbObjArray = new BasicDBObject[2]
dbObjArray[0]= cruxLevel
dbObjArray[1] = project
List<DBObject> pipeline = Arrays.asList(dbObjArray)
if (!datasetobject?.isFlat && jsonFor != 'collection-grid') {
output= dataSetCollection.aggregate(pipeline)
}else{
output= dataSetCollection.aggregate(project)
}
output.results().eachWithIndex{list,index->
dataList.add(output.results()[index])
我在下面尝试过在游标中获取结果.
1.
// Assuming MongoCollection
dataSetCollection.aggregate(pipeline).useCursor(true)
您可能还需要告诉它使用服务器上的磁盘空间,而不是全部在内存中完成:
2.
// Assuming MongoCollection
dataSetCollection.aggregate(pipeline).useCursor(true).allowdiskUse(true)
如果您使用的是旧版驱动程序(或新版驱动程序中的旧API),则这两个选项将如下所示:
3.
// Assuming DBCollection
dataSetCollection.aggregate(pipeline, Aggregationoptions.builder().allowdiskUse(true)
.useCursor(true)
.build())
.useCursor(true)
和
output= dataSetCollection.aggregate(project).newAggregationoptions().outputMode(Aggregationoptions.OutputMode.CURSOR).build()
以错误为例
对于“输出= dataSetCollection.aggregate(项目).useCursor(true)”
groovy.lang.MissingMethodException: No signature of method: com.mongodb.AggregationOutput.useCursor() is applicable for argument types: (java.lang.Boolean) values: [true]
对于“输出= dataSetCollection.aggregate(项目).useCursor(true).allowdiskUse(true)”
groovy.lang.MissingMethodException: No signature of method: com.mongodb.AggregationOutput.useCursor() is applicable for argument types: (java.lang.Boolean) values: [true]
对于“输出= dataSetCollection.aggregate(project,Aggregationoptions.builder()
.allowdiskUse(true)
.useCursor(真实)
.建立())
.useCursor(true)”
groovy.lang.MissingPropertyException: No such property: Aggregationoptions for class: com.acumetric.hrat.aggregator.DataimportService
最后一个.
groovy.lang.MissingMethodException: No signature of method: com.mongodb.AggregationOutput.newAggregationoptions() is applicable for argument types: () values: []
什么都没用.我要去哪里了,请帮忙!
谢谢.
解决方法:
在else块下面的代码中
def dbObjArray = new BasicDBObject[1]
dbObjArray[0]= project
List<DBObject> flatPipeline = Arrays.asList(dbObjArray)
Aggregationoptions aggregationoptions = Aggregationoptions.builder()
.batchSize(100)
.outputMode(Aggregationoptions.OutputMode.CURSOR)
.allowdiskUse(true)
.build();
def cursor = dataSetCollection.aggregate(flatPipeline,aggregationoptions)