Java Spring数据MongoDB和allowDiskUse
我有这样一个问题:Java Spring数据MongoDB和allowDiskUse,java,spring,mongodb,Java,Spring,Mongodb,我有这样一个问题: db.tqaP.aggregate([ {$match : { $and: [ {"eventUTCDate" : { $gte : '01-10-2014' }
db.tqaP.aggregate([
{$match : { $and: [
{"eventUTCDate" : {
$gte : '01-10-2014'
}
},
{"eventUTCDate" : {
$lt : '31-10-2014'
}
},
{"mpTransactionId":{
$exists: true
}
},
{testMode : false},
{eventID : {
$in : [
230, // ContentDiscoveredEvent
204, // ContentSLAStartEvent
211, // ContentProcessedEndEvent
255, // ContentValidationStatusEvent
256, // ContentErrorEvent
231, // ContentAnalyzedEvent
240, // ContentTranscodeStartEvent
241, // ContentTranscodeEndEvent
252 // AbortJobEvent
//205, 207
]
}
}
]}},
{$project :
{
_id:0,
event : {
eventID : "$eventID",
eventUTCDate : "$eventUTCDate",
processState : "$processState",
jobInstanceId : "$jobInstanceId",
mpTransactionId : "$mpTransactionId",
eventUID : "$eventUID",
contextJobInstanceId : "$context.jobInstanceId",
contextValidationStatus : "$context.validationStatus",
metaUpdateOnly : "$metaUpdateOnly",
errorCode : "$errorCode",
transcodingProfileName : "$transcodingProfileName",
contextAssetId : "$context.assetId"
}
}
},
// Creating the hash map <mpTransactionId, listOfAssociatedEvents>
{$group : {
"_id" : "$event.mpTransactionId",
"chainOfEvents" : {$addToSet : "$event"}
},
},
// Sorting by chainOfEvents.eventUTCDate
{$unwind : "$chainOfEvents"},
{$sort : {
"chainOfEvents.eventUTCDate":1
}
},
{$group : {
_id :"$_id",
chainOfEvents: {
$push:"$chainOfEvents"
}
}
}
])
我通过在最后一个结束括号(正方形和圆形括号)之间添加
现在,我正尝试使用Spring数据为MongoDB表达同样的内容,我的Java代码如下所示:
MatchOperation match = Aggregation.match( new Criteria()
.andOperator(
Criteria.where("eventUTCDate").gte(startDateAsString),
Criteria.where("eventUTCDate").lt(endDateAsString))
.and("mpTransactionId").exists(true)
.and("testMode").is(false)
.and("eventID").in(230, 204, 211, 255, 256, 231, 240, 241, 252) );
ProjectionOperation projection = Aggregation.project().and("event").
nested(bind("eventID", "eventID").
and("eventUTCDate", "eventUTCDate").
and("processState", "processState").
and("jobInstanceId", "jobInstanceId").
and("mpTransactionId", "mpTransactionId").
and("eventUID", "eventUID").
and("contextJobInstanceId", "context.jobInstanceId").
and("contextValidationStatus", "context.validationStatus").
and("metaUpdateOnly", "metaUpdateOnly").
and("errorCode", "errorCode").
and("transcodingProfileName", "transcodingProfileName").
and("contextAssetId", "context.assetId"));
GroupOperation group = Aggregation.group("event.mpTransactionId").addToSet("event").as("chainOfEvents");
UnwindOperation unwind = Aggregation.unwind("chainOfEvents");
SortOperation sort = Aggregation.sort(Sort.Direction.ASC, "chainOfEvents.eventUTCDate");
GroupOperation groupAgain = Aggregation.group("_id").push("chainOfEvents").as("eventsList");
Aggregation agg = newAggregation(Event.class, match, projection, group, unwind, sort, groupAgain).withOptions(Aggregation.newAggregationOptions().allowDiskUse(true).build());
AggregationResults<EventsChain> results = mongoOps.aggregate(agg, "tqaP", EventsChain.class);
以适应数据的大小。有人能告诉我是不是用错了吗
我正在使用MongoDB 2.6.4和Spring Data MongoDB 1.6.1-RELEASE。我看到了代码,它用2147483647硬编码了batchSize,您可以使用:
AggregationOptions options = AggregationOptions.builder().allowDiskUse(true).batchSize(100).build();
mongo.getCollection("COLLECTION").aggregate(list, options);
这管用 下面是一个使用
MongoTemplate
class helper的工作解决方案2.1.8
AggregationOptions options = AggregationOptions.builder().allowDiskUse(true).build();
List<AggregationOperation> aggs = Arrays.asList(m1, p1, g1);
mongoTemplate.aggregate(Aggregation.newAggregation(aggs).withOptions(options), inputCollectionName, Document.class);
AggregationOptions-options=AggregationOptions.builder().allowDiskUse(true.build();
List aggs=Arrays.asList(m1、p1、g1);
aggregate(Aggregation.newAggregation(aggs).withOptions(options),inputCollectionName,Document.class);
我在使用3.4版时遇到了同样的问题。你已经得到你的解决方案了吗?
.withOptions(Aggregation.newAggregationOptions().allowDiskUse(true).build());
AggregationOptions options = AggregationOptions.builder().allowDiskUse(true).batchSize(100).build();
mongo.getCollection("COLLECTION").aggregate(list, options);
AggregationOptions options = AggregationOptions.builder().allowDiskUse(true).build();
List<AggregationOperation> aggs = Arrays.asList(m1, p1, g1);
mongoTemplate.aggregate(Aggregation.newAggregation(aggs).withOptions(options), inputCollectionName, Document.class);