简体   繁体   English

使用WSO2EI和MongoDB进行自定义聚合

[英]Custom aggregation with WSO2EI and MongoDB

I'm tring to implement aggregation operations for Mongo data service in WSO2DSS (in WSO2EI) since only the basic operations like CRUD and Count are supported out of the box as mentioned here . 我特林实施蒙戈数据服务WSO2DSS聚合操作(在WSO2EI),因为只有像CRUD的基本操作和计数提到支持开箱即在这里 So I cloned WSO2EI code version 4.4.10 (our team happens to be using this version) and I've successfully added some of my own functionality. 因此,我克隆了WSO2EI代码版本4.4.10 (我们的团队恰好使用了该版本),并且我成功添加了一些自己的功能。 However, whenever I try to use org.jongo.MongoCollection.aggregate() function, I get error Error in MongoQuery.runQuery: Command failed with error 9: 'The 'cursor' option is required, except for aggregate with the explain argument' . 但是,每当我尝试使用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' I checked all the posts regarding this issue and tried to use different versions of Mongo driver (3.4, 3.6..), also changed the actual syntax a lot but no matter what I try, I always get this error if I use the .aggregate() function. 我检查了有关此问题的所有帖子,并尝试使用不同版本的Mongo驱动程序(3.4、3.6 ..),还对实际语法进行了很多更改,但是无论我尝试什么,如果我使用.aggregate() ,我总是会收到此错误.aggregate()功能。 Also should I be using org.jongo.MongoCollection.aggregate(String pipelineOperator) or com.mongodb.async.client.aggregate(java.util.List<? extends Bson> pipeline) as stated in the Mongo Java 3.6 documentation here . 还我应该使用org.jongo.MongoCollection.aggregate(String pipelineOperator)com.mongodb.async.client.aggregate(java.util.List<? extends Bson> pipeline)作为蒙戈的Java 3.6文档中所述这里 Example code I used: 我使用的示例代码:

private Iterator<MongoTestClass> doAggregate1(MongoCollection collection, String opQuery, Object[] parameters) throws DataServiceFault {

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

    }

where componentType is existing field in my MongoDB collection document and 'Endpoint' is it's value. 其中componentType是我的MongoDB集合文档中的现有字段,而'Endpoint'是它的值。 Is my actual synatax wrong? 我的实际概要错误吗? Or is there any other problem? 还是还有其他问题? How can I add the 'cursor' to my query so the error goes away? 如何将'cursor'添加到查询中,以使错误消失?

I can't wrap my head around how this works...much appreciate any help. 我无法确定这是如何工作的...非常感谢您的帮助。

From the docs. 从文档。

MongoDB 3.4 deprecates the use of aggregate command without the cursor option, unless the pipeline includes the explain option. MongoDB 3.4不建议使用不带游标选项的聚合命令,除非管道包括解释选项。 When returning aggregation results inline using the aggregate command, specify the cursor option using the default batch size cursor: {} or specify the batch size in the cursor option cursor: { batchSize: }. 使用Aggregation命令以内联方式返回聚合结果时,请使用默认的批处理大小游标{}指定游标选项,或在游标选项游标{{BatchSize:}中指定批处理大小。

You can pass batchSize with AggregationOptions for Jongo Aggregate method. 您可以将带有AggregationOptions batchSize传递给batchSize Aggregate方法。

AggregationOptions options = AggregationOptions.builder().options.
     batchSize(100).
     outputMode(AggregationOptions.OutputMode.CURSOR).build();

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

With default batch size 使用默认批次大小

AggregationOptions options = AggregationOptions.builder().options.
     outputMode(AggregationOptions.OutputMode.CURSOR).build();

OR 要么

AggregationOptions options = AggregationOptions.builder().build();

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM