首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用WSO2EI和MongoDB的自定义聚合

使用WSO2EI和MongoDB的自定义聚合
EN

Stack Overflow用户
提问于 2018-02-26 13:44:45
回答 1查看 267关注 0票数 1

我尝试在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文档这里中所述。我使用的示例代码:

代码语言:javascript
复制
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是如何感谢任何帮助的。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-02-26 14:29:37

从医生那里。

MongoDB 3.4不赞成使用聚合命令而不使用游标选项,除非管道包括解释选项。当使用聚合命令内联返回聚合结果时,使用默认批处理大小游标:{}指定游标选项,或在游标选项游标中指定批处理大小:{ batchSize:}。

您可以将batchSizeAggregationOptions一起传递给Jongo聚合方法。

代码语言:javascript
复制
AggregationOptions options = AggregationOptions.builder().options.
     batchSize(100).
     outputMode(AggregationOptions.OutputMode.CURSOR).build();

collection.aggregate("{$match:{componentType:'Endpoint'}}").options(options).as(MongoTestClass.class).iterator();

具有默认的批次大小

代码语言:javascript
复制
AggregationOptions options = AggregationOptions.builder().options.
     outputMode(AggregationOptions.OutputMode.CURSOR).build();

代码语言:javascript
复制
AggregationOptions options = AggregationOptions.builder().build();

collection.aggregate("{$match:{componentType:'Endpoint'}}").options(options).as(MongoTestClass.class).iterator();
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/48989991

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档