我正在尝试使用Morphia(1.3.2)聚合MongoDB(3.6) .

目前,理解Morphia的API是一个简单的匹配和放松 .

然而,我面临的问题与MongoDB 3.6有关:


版本3.4中更改:除非命令包含explain选项,否则MongoDB 3.6将删除不带游标选项的aggregate命令的使用 . 除非包含explain选项,否则必须指定cursor选项 .


本段直接来自MongoDB文档 . MongoDB Aggregate .

这意味着必须使用游标才能使聚合工作 . 但是,我找不到使用Morphia做到这一点的方法 . 因此我的聚合不起作用 .

AggregationPipeline data = aggregation.match(query).unwind("data");

 Iterator<LoraHourData> out = data.aggregate(Data.class);

使用上面的代码产生的错误如下:

Command failed with error 9: The cursor option is required,     except for aggregate with the explain argument on server localhost:27017. The full response is { ok : 0.0, errmsg: The cursor option is required, except for aggregate with the explain argument&quot;, code : 9, codeName : FailedToParse }