我尝试在WSO2DSS (在WSO2EI中)中为Mongo数据服务实现聚合操作,因为像CRUD和Count这样的基本操作就像前面提到的这里那样只支持开箱即用。所以我克隆了WSO2EI代码版本4.4.10 (我们的团队恰好使用了这个版本),并且成功地添加了我自己的一些功能。但是,每当我尝试使用org.jongo.MongoCollection.aggregate()函数时,都会得到错误Error in MongoQuery.runQuery: Command failed with error 9: 'The 'cursor' option is required, except for aggregate with the explain argument'。我检查了所有关于这个问题的帖子,尝试使用不同版本的Mongo驱动程序(3.4,3.6.),也更改了很多实际语法,但是无论我尝试什么,如果我使用.aggregate()函数,我总是会得到这个错误。此外,我是否应该使用org.jongo.MongoCollection.aggregate(String pipelineOperator)或com.mongodb.async.client.aggregate(java.util.List<? extends Bson> pipeline),如MONGOJava3.6文档这里中所述。我使用的示例代码:
private Iterator<MongoTestClass> doAggregate1(MongoCollection collection, String opQuery, Object[] parameters) throws DataServiceFault {
return collection.aggregate("{$match:{componentType:'Endpoint'}}")
.as(MongoTestClass.class).iterator();
}其中componentType是我的MongoDB集合文档中的现有字段,'Endpoint'是它的值。我真的是错了吗?或者还有其他问题吗?如何将'cursor'添加到查询中,从而消除错误?
我无法理解这个works...much是如何感谢任何帮助的。
发布于 2018-02-26 14:29:37
从医生那里。
MongoDB 3.4不赞成使用聚合命令而不使用游标选项,除非管道包括解释选项。当使用聚合命令内联返回聚合结果时,使用默认批处理大小游标:{}指定游标选项,或在游标选项游标中指定批处理大小:{ batchSize:}。
您可以将batchSize与AggregationOptions一起传递给Jongo聚合方法。
AggregationOptions options = AggregationOptions.builder().options.
batchSize(100).
outputMode(AggregationOptions.OutputMode.CURSOR).build();
collection.aggregate("{$match:{componentType:'Endpoint'}}").options(options).as(MongoTestClass.class).iterator();具有默认的批次大小
AggregationOptions options = AggregationOptions.builder().options.
outputMode(AggregationOptions.OutputMode.CURSOR).build();或
AggregationOptions options = AggregationOptions.builder().build();
collection.aggregate("{$match:{componentType:'Endpoint'}}").options(options).as(MongoTestClass.class).iterator();https://stackoverflow.com/questions/48989991
复制相似问题